The attribute is optional if it is possible and valid to be null. Properties of CLR types that are not null cannot be configured as optional.
An example usage of optional attributes:
[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; } }
The above is the detailed content of Optional properties in C# classes. For more information, please follow other related articles on the PHP Chinese website!