C# 類中的可選屬性
如果可能並且允許為其提供 null,則屬性為可選。CLR 型別不能為 null 的屬性不能配置為可選。
可選屬性使用示例 −
示例
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] internal sealed class OptionalAttribute : Attribute { } public class Employee { public string EmpName { get; set; } [Optional] public string AlternativeName { get; set; } }
廣告