![](/img/trans.png)
[英]Why do some assembly references have a version and others not when added through NuGet
[英]Why do some DataMember attributes have brackets while others have not?
有關DataMemberAttribute類的MSDN文檔顯示了以下示例。
有時設置了括號,有時沒有設置。 背后的原因是什么?
例:
[DataMember()]
public string FirstName;
[DataMember]
public string LastName
{
get { return LastNameValue; }
set { LastNameValue = value; }
}
這是C#語法問題。 它與這些特定的類無關。
如果不將參數傳遞給屬性的構造函數,則括號對於屬性是可選的。
我建議您決定喜歡哪種風格並堅持使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.