日期:2014-05-20 浏览次数:20837 次
class MainClass { // Regular method that matches signature: static void SampleDelegateMethod(string message) { Console.WriteLine(message); } static void Main() { // Instantiate delegate with named method: SampleDelegate d1 = SampleDelegateMethod; // Instantiate delegate with anonymous method: SampleDelegate d2 = delegate(string message) { Console.WriteLine(message); }; // Invoke delegate d1: d1("Hello"); // Invoke delegate d2: d2(" World"); } }