此代码示例中的@是什么意思?
Html.TextBox("ParentPassword", "", new { @class = "required" })
天哪,@class 的@。
Html.TextBox("ParentPassword", "", new { @class = "required" })
what the gosh darned heck is the @ for the @class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
class
是保留关键字,因此不能将其用作变量名。@ 运算符允许您绕过此规则。 此处这样做的原因是匿名对象用于填充 HTML 元素上的属性。 有效的属性名称是“class”,它允许您在元素上设置 CSS 类。
class
is a reserved keyword, so you can't use this as a variable name.The @ operator allows you to get around this rule. The reason why its being done here is that the anonymous object is used to populate attributes on a HTML element. A valid attribute name is "class", which lets you set the CSS class on the element.
class
是一个关键字。 要在 C# 中使用class
作为变量/属性的名称,您可以在其前面添加@
,如@class
。 在 IL 中,对于所有 .net 而言,变量/属性的名称仍然是class
-@
是在 C# 中必须这样做的方式。class
is a keyword. To useclass
as the name of a variable/property, in C#, you can prepend@
to it, as@class
. In the IL, for all .net is concerned, the name of the variable/property is stillclass
-@
is the way you have to do it in C#.只是为了在这里为所有正确答案添加我的两分钱:
如果您是 C# 新手但熟悉 VB.NET,您可能知道 VB 中有一个与 @ 对应的对象。 在 VB.NET 中,方括号 [ ] 用于包围以保留字(或关键字)命名的变量名。 例如:
Just to add my two cents to all the right answers here:
If you are new to C# but familiar to VB.NET, you probably know that there is a correspondent to @ in VB. The square brackets [ ] are used in VB.NET to surround a variable name that is named after a reserved word (or keyword). For example: