|
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
|