C#: Anonymous method vs Named method

后端 未结 5 1457
渐次进展
渐次进展 2020-12-10 05:19

I\'m new to SO and programming and learning day by day with bits and pieces of tech (C#) jargons.

After Googling for a while, below is what I\'ve researched about

5条回答
  •  生来不讨喜
    2020-12-10 06:00

    Let's start from a simple method.

    void MyMethod()
    {
      Console.WriteLine("Inside MyMethod"); //Write to output
    }
    

    The above method is a named-method which just writes Inside MyMethod to the output window.

    Anonymous methods are some methods used in some special scenarios (when using delegates) where the method definition is usually smaller where you don't specify the name of the method.

    For example, (delegate) => { Console.WriteLine("Inside Mymethod");}

    Just start writing some simple programs and in the due course, when you use delegates or some advanced concepts, you will yourself learn. :)

提交回复
热议问题