次のサンプル コードを考えます。
static void SomeMethod()
{
Action<int,int> myDelegate;
//...
myDelegate = delegate { Console.WriteLine( 0 ); };
myDelegate = delegate() { Console.WriteLine( 0 ); }; // compile error
}
違いは何ですか
myDelegate = delegate { Console.WriteLine( 0 ); };
と
myDelegate = delegate() { Console.WriteLine( 0 ); };
?
この例では、2 番目のステートメントはコンパイル エラーを生成しますが、最初のステートメントは生成しません。