关于委托,为啥有个分号???????
using System;
// Declare delegate -- defines required signature:
delegate void SampleDelegate(string message);
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 ");
}
}
------解决方案--------------------用匿名方法实例化委托是一个完整的赋值表达式,自然以 ; 结束