C# – Anonymous delegate

cdelegates

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

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();
        }
    }
}

Best Answer

There's no such thing as an "anonymous delegate" (or rather, that's not a recognised term in the C# specification, or any other .NET-related specification I'm aware of).

There are anonymous functions which include anonymous methods and lambda expressions.

Your code shows plain old anonymous methods - although they are using the one feature lambda expressions don't have: the ability to not express the parameters at all when you don't care about them.

Related Topic