简体   繁体   中英

workflow window foundation =()=>

What does = () => mean in c#?

I've used lambda's before but those empty parens () are throwing me off.

Familiar with this:

customers.Find(x=>x.FirstName=="John")

Article resource

在此处输入图片说明

It's assigning a lambda expression to the variable or property 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.

This is known as a lambda expression. In essence, it's shorthand for defining a function.

Here is a decent tutorial explaining the concept:

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

This lambda is assigned to this.Implementation so that at a later time you can call the lambda. Eg, 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. 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 () . You can see more in the documentation.

The = before the lambda call is assigning the method body that follows to the Implementation property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM