将对象中的方法映射成委托
using System;
namespace CreateDelegateTest {
class Program {
public delegate void DelegateDisplay( string s );
static void Main( string[] args ) {
TestClass test = new TestClass();
//将test对象中的Display(string s)映射成委托对象
DelegateDisplay display = ( DelegateDisplay )System.Convert.ChangeType( System.Delegate.CreateDelegate( typeof( DelegateDisplay ), test, "Display" ), typeof( DelegateDisplay ) );
display("test!!!!");
Console.Read();
}
}
class TestClass {
public void Display(string s) {
Console.WriteLine(s);
}
}
}