C# - Anonymous delegate

前端 未结 7 1812
有刺的猬
有刺的猬 2021-02-07 08:00

Like Anonymous Methods ,the delegates i am declaring down using \"delegate\" keyword are anonymous delegates?

namespace Test
{
    public delegate void MyDelegat         


        
7条回答
  •  日久生厌
    2021-02-07 08:21

    That's correct, you have assigned a number of anonymous methods to an event.

    If you're using a newer version of c#, you can also do something similar with lambdas. for example:

    class DelegateTest
    {
        public event Action del;
    
        public void Chaining()
        {
            del += () => Console.WriteLine("Hello World");
            del += () => Console.WriteLine("Good Things");
            del += () => Console.WriteLine("Wonderful World");
            del();
        }
    }
    

提交回复
热议问题