Home
Browsez les 647 exemples
Téléchargez les 647 exemples
Téléchargez des chapitres
Achetez sur amazon.fr

Niveau: Débutant/Intermédiaire
ISBN-2-84177-339-6
50 Euros

Exemple 13-15 extrait du chapitre La généricité


Exemple 13-14<     > Exemple 13-16


Cet exemple peut être compilé avec la ligne de commande:
csc.exe /target:exe Exemple_13_15.cs
Erreurs: 0 Avertissements: 0
Remarque:


Exemple_13_15.cs
using System;
class C<T> {
   private static int m_NInst = 0;
   public C() { m_NInst++; }
   public int NInst { get return m_NInst; } }
}
class Program {
   static void Main() {
      C<int>    c1 = new C<int>(); 
      C<int>    c2 = new C<int>(); 
      C<int>    c3 = new C<int>();
      C<string> c4 = new C<string>(); 
      C<string> c5 = new C<string>(); 
      C<object> c6 = new C<object>();
      Console.WriteLine( "NInst C<int>   : " + c1.NInst.ToString() );
      Console.WriteLine( "NInst C<string>: " + c4.NInst.ToString() );
      Console.WriteLine( "NInst C<object>: " + c6.NInst.ToString() );
   }
}	
Copyright Patrick Smacchia 2006 2007