开发者

What does '_' stands for in Razor?

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 => function is 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.User means define a one parameter function that maps any parameter to item.User.

Lambda Expressions (C# Programming Guide)

=> Operator (C# Reference)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜