What does ‘ _ ‘ stands for in the below code? I was trying the new scaffolding and it generates the below code. However, I’m not sure what ‘ _ ‘ used for.
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayTextFor(_ => item.User).ToString()
</td>
</tr>
}
This is not Razor specific. And that it’s a
_isn’t significant either. It’s just a valid identifier for a parameter of a lambda.identifier => functionis the form of a single parameter lambda. And_happens to be a valid identifier. In this case the author most likely wants to indicate that the parameter doesn’t matter to him, using the name_._ => item.Usermeans define a one parameter function that maps any parameter toitem.User.Lambda Expressions (C# Programming Guide)
=>Operator (C# Reference)