简体   繁体   English

为什么某些DataMember属性带有方括号,而另一些则没有?

[英]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.

相关问题 为什么有些程序集引用有一个版本,有些则不是通过NuGet添加的 - Why do some assembly references have a version and others not when added through NuGet 为什么属性的属性必须是可读的? - Why do properties of attributes have to be readable? 为什么有些饼干有'。' 领域之前? - Why do some cookies have a '.' before the domain? 如何在DataContract中使用条件DataMember? - How to have conditional DataMember in a DataContract? 为什么有些类型没有文字修饰符 - Why some types do not have literal modifiers 为什么有些管理器可以用作类类型,而其他管理器必须是对象类型 - Why some managers can be used as a class type, but the others have to be an object type 为什么Blazor组件和元素没有Id属性 - Why do Blazor components and elements not have Id attributes 为什么某些异步方法具有异步而其他异步方法却没有 - Why some async methods have async while other don't 为什么有些行在C#中没有分号? - why do some lines not have semicolon in C#? 只有某些WCF SVC方法具有匿名访问权限,而其他方法具有Windows安全性吗? - Have only certain WCF SVC methods have anonymous access while the others have windows security?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM