Title: How do C# lambdas work without a “return”?
Tags: c#;lambda
Question: I have occasionally come across statements like this

```school.Where(s =&gt; s.name == "foo") 
```

Now I understand this is a lambda and I think I am comfortable with lambdas. I just started C# so I do have this question. In the statement

```s =&gt; s.name == "foo"
```

how is the evaluation return being done to determine true or false. I do not see a return statement ? All i see is a comparison operation in the lambda body and nothing being returned. Can anyone please explain this to me.


Here is the accepted answer: In this form the return is implicit. The lambda returns whatever the expression returns. You could also write it like this:

```s =&gt; { return s.name == "foo"; }
```

The reason why the return isn’t needed in the short form is because that’s how the language was designed. It makes things short and nice to use instead of forcing the developer to write unnecessary code. 

Comment for this answer: Right. Just as reference: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-operator

Here is another answer: The returned value is always boolean and you can get it like below:

```s=&gt; {retutn s.name=="foo";}
```


Here is another answer: The return statement is implied. If you were to add brackets around ```s.name == "foo"``` then you'd have to have a return. The compiler essentially creates a function to be called there for you. This is just syntax sugar. It's equivalent to creating a function yourself and passing that into the Where


Here is another answer: Lambda can be defined in two ways:


with curly braces: then you will have to write body of a method, just like in a regular method, i.e. with ```return```s, etc. Example

```var lambda = (string param) =&gt; { return param.Length; };
```
without curly braces: then the method has to contain one line, which also be the result of a method. Example:

```var lambda = (string param) =&gt; param.Length;
```


This is by design, to make one-line methods look nice and clean (especially in LINQ extensoin methods) :)


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 4, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:10/09/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c#><lambda>', 'Title': 'How do C# lambdas work without a “return”?', 'ViewCount': 78, 'id': 58297114, 'user_AboutMe': '', 'user_AccountId': 967281.0, 'user_DisplayName': 'MistyD', 'user_Reputation': 15183.0, 'user_Views': 1607.0, 'user_id': 990502.0}}