Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press

Buy directly from Paradoxal Press at $33.99 (Save 43%)



Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA


Listing 13-28 extracted from chapter Generics


Listing 13-27<     > Listing 13-29


This listing can be compiled with the command line:
csc.exe /target:exe Example_13_28.cs
Errors: 0 Warnings: 1


Example_13_28.cs
class C1 {
   public U Fct<U>(U u) { return u; }
}
class C2<T> {
   public U Fct<U>(U u) { return u; }
   public static U FctStatic<U>(U u) { return u; }
}
class C3<T> {
   // Compilation warning : Type parameter ' T' has same
   // name as type parameter from outer type 'C3<T>'.
   public T Fct<T>(T t) { return t; }
}
class Program {
   static void Main() {
      C1 c1 = new C1();
      c1.Fct<double>(3.4);
      C2<int> c2 = new C2<int>();
      c2.Fct<double>(3.4);
      c2.Fct<string>("hello");
      C3<int> c3 = new C3<int>();
      c3.Fct<double>(3.4);
   }
}	
Copyright Patrick Smacchia 2006 2007