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; }
}
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP