[英]workflow window foundation =()=>
What does = () =>
mean in c#? = () =>
在C#中是什么意思?
I've used lambda's before but those empty parens ()
are throwing me off. 我以前用过lambda,但是那些空的paren
()
却使我失望。
Familiar with this: 熟悉此:
customers.Find(x=>x.FirstName=="John")
It's assigning a lambda expression to the variable or property this.Implementation. 它将lambda表达式分配给变量this.Implementation。 You have to break down the operators like this:
您必须像这样分解运算符:
this.Implementation
= //assignment operator
()=> new Sequence { /* stuff */ };
The () is to designate that the method takes no parameters; ()表示该方法不带参数; the => identifies what follows as the code to be run when the lambda is invoked.
=>标识调用lambda时要运行的代码。
This is known as a lambda expression. 这称为lambda表达式。 In essence, it's shorthand for defining a function.
本质上,它是定义函数的简写。
Here is a decent tutorial explaining the concept: 这是解释这个概念的不错的教程:
http://www.dotnetperls.com/lambda http://www.dotnetperls.com/lambda
The () => new Sequence
part along with the block below it is an lambda function that takes no parameters and return a Sequence
() => new Sequence
部分及其下面的块是一个lambda函数,不带任何参数并返回Sequence
This lambda is assigned to this.Implementation
so that at a later time you can call the lambda. 该lambda分配给了
this.Implementation
以便以后可以调用lambda。 Eg, var s = this.Implementation()
. 例如,
var s = this.Implementation()
。
The ()
simply means the anonymous method has no parameters. ()
仅表示匿名方法没有参数。 The way you're used to seeing, like customers.Find(x=>x.FirstName == "John")
is the same... the first x
is the parameter passed to the lambda. 您惯用的查看方式(例如
customers.Find(x=>x.FirstName == "John")
是相同的...第一个x
是传递给lambda的参数。 The parentheses are optional if there's only a single parameter, so this could also be written like this: customers.Find((x)=>x.FirstName == "John")
With a method that takes no parameters, the 'single parameter' exclusion doesn't apply, so you have to write the ()
. 如果只有一个参数,则括号是可选的,因此也可以这样写:
customers.Find((x)=>x.FirstName == "John")
使用不带参数的方法,即“单个参数” '排除不适用,因此您必须编写()
。 You can see more in the documentation. 您可以在文档中看到更多信息。
The =
before the lambda call is assigning the method body that follows to the Implementation
property. lambda调用之前的
=
将后面的方法主体分配给Implementation
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.