|
Listing 13-37 extracted from chapter
Generics
Listing 13-36< > Listing 13-38
This listing can be compiled with the command line: csc.exe /target:exe Example_13_37.cs Errors: 0 Warnings: 0
Example_13_37.cs
class Base { }
class Derived : Base { }
delegate B DelegateType<B,D>(D d);
class Program {
static Derived Handler(Base b){return b as Derived;}
static void Main() {
DelegateType<Base, Derived> delegateInstance = Handler;
// The in reference is implitly casted from 'Derived' to 'Base'.
// The out reference is implitly casted from 'Derived' to 'Base'.
Base b = delegateInstance( new Derived() );
}
}
Copyright Patrick Smacchia 2006 2007
|