Với mã mẫu sau:Chỉ định phương thức ẩn danh để ủy nhiệm sử dụng dấu ngoặc đơn cho lỗi trình biên dịch?
static void SomeMethod()
{
Action<int,int> myDelegate;
//...
myDelegate = delegate { Console.WriteLine(0); };
myDelegate = delegate() { Console.WriteLine(0); }; // compile error
}
sự khác biệt giữa
myDelegate = delegate { Console.WriteLine(0); };
và
myDelegate = delegate() { Console.WriteLine(0); };
là gì?
Trong ví dụ này, câu lệnh thứ hai tạo ra lỗi biên dịch trong khi lệnh đầu tiên thì không.