你如何定义Lambdas运算符? => [英] How do you define the Lambdas operator? =>

查看:93
本文介绍了你如何定义Lambdas运算符? =>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。 lambda操作符究竟是什么,我应该如何在脑中定义它?例如:

Hello. What exactly is the lambdas operator, and how should I define it in my head? For example:

x = y; //x is the same number as y.

if (x != y) //if x and y are different numbers do this, this, and this.
{
//this, this, and this
}
//How should I read this?
if (currentRoom.roomEnemies.Count(roomEnemies => roomEnemies != null) == 0)
{
Console.WriteLine("There are no enemies in here.");
}



更多例子会很棒。提前谢谢你。


Some more examples would be great. Thank you in advance.

推荐答案

所有的lambda都是一个伸出来的方法。

All a lambda is, is a method that has been "stretched out".
x => x + 1;

是等效的写作

Is the equivalent of writing

private int MyMethod(int x)
   {
   return x + 1;
   }



除了使用它们之外,它们还有很多(例如,整个Linq依赖于它们),但是要了解详细信息,请参阅MSDN: Lambda表达式(C#编程指南) [ ^ ]


这篇关于你如何定义Lambdas运算符? =>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆