[英]Why do some DataMember attributes have brackets while others have not?
The MSDN documentation about the DataMemberAttribute class shows a example below. 有关DataMemberAttribute类的MSDN文档显示了以下示例。
Sometimes brackets are set and sometimes are not. 有时设置了括号,有时没有设置。 What is the reason behind? 背后的原因是什么?
Example: 例:
[DataMember()]
public string FirstName;
[DataMember]
public string LastName
{
get { return LastNameValue; }
set { LastNameValue = value; }
}
This is a C# syntax issue. 这是C#语法问题。 It has nothing to do with these particular classes. 它与这些特定的类无关。
Brackets are optional for attributes if you do not pass arguments to the constructor of the attribute. 如果不将参数传递给属性的构造函数,则括号对于属性是可选的。
I recommend that you decide which style you like and stick to it. 我建议您决定喜欢哪种风格并坚持使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.