Giống như các Phương thức ẩn danh, các đại biểu mà tôi đang khai báo sử dụng từ khóa "đại biểu" là các đại biểu ẩn danh?C# - Người được ủy quyền vô danh
namespace Test
{
public delegate void MyDelegate();
class Program
{
static void Main(string[] args)
{
DelegateTest tst = new DelegateTest();
tst.Chaining();
Console.ReadKey(true);
}
}
class DelegateTest
{
public event MyDelegate del;
public void Chaining()
{
del += delegate { Console.WriteLine("Hello World"); };
del += delegate { Console.WriteLine("Good Things"); };
del += delegate { Console.WriteLine("Wonderful World"); };
del();
}
}
}
Biểu thức Lambda và các phương thức ẩn danh trong cú pháp lambda không thực sự giống nhau. Câu lệnh của bạn là đúng nếu bạn sử dụng cú pháp lambda với các dấu ngoặc nhọn: (x) => {y();} – Lucero