【发布时间】:2012-12-16 19:24:51
【问题描述】:
下面代码中的方括号是什么意思:
public class LoginModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
我在其他问题中读到它们是属性,但我不知道它们是如何工作的..为什么它们会出现在这个类中? 这些是否仅在 C# 中使用?
【问题讨论】:
-
.NET: What are attributes? 的可能副本另请参阅:Attributes in C#
标签: c# model square-bracket