C# Lambda expressions: Why should I use them?

后端 未结 15 1587
栀梦
栀梦 2020-11-22 03:51

I have quickly read over the Microsoft Lambda Expression documentation.

This kind of example has helped me to understand better, though:

delegate in         


        
15条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 04:16

    Lambda's cleaned up C# 2.0's anonymous delegate syntax...for example

    Strings.Find(s => s == "hello");
    

    Was done in C# 2.0 like this:

    Strings.Find(delegate(String s) { return s == "hello"; });
    

    Functionally, they do the exact same thing, its just a much more concise syntax.

提交回复
热议问题