|
Listing 14-33 extracted from chapter Unsafe code, exceptions, anonymous methods, iterators
Listing 14-32< > Listing 14-34
This listing can be compiled with the command line: csc.exe /target:exe Example_14_33.cs Errors: 0 Warnings: 0
Example_14_33.cs
class Program {
delegate void DelegateType( int writeNTime );
// This method is public to avoid problems of reflection
// on a non-public member.
public static void WriteLineNTimes( string s, int nTime ) {
for( int i=0; i<nTime; i++ )
System.Console.WriteLine( s );
}
static void Main() {
DelegateType deleg = System.Delegate.CreateDelegate(
typeof( DelegateType ),
"Hello",
typeof(Program).GetMethod( "WriteLineNTimes" )) as DelegateType;
deleg(4);
}
}
Copyright Patrick Smacchia 2006 2007
|