Is there a case where delegate syntax is preferred over lambda expression for anonymous methods?

前端 未结 7 1524
别跟我提以往
别跟我提以往 2021-02-07 21:13

With the advent of new features like lambda expressions (inline code), does it mean we dont have to use delegates or anonymous methods anymore? In almost all the samples I have

7条回答
  •  醉梦人生
    2021-02-07 21:49

    lambda is shortcut for anonymous delegate, but you will always be using delegates. the delegate specifies the methods signature. you can just do this:

     delegate(int i) { Console.WriteLine(i.ToString()) }
    

    can be replaced with

    f => Console.WriteLine(f.ToString())
    

提交回复
热议问题