Optional property in a C# class

CsharpProgrammingServer Side Programming

A property is optional if it is possible and valid for it to have null. A property whose CLR type cannot have null cannot be configured optional.

An example optional attribute usage −

Example

[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; }
}
raja
Published on 14-Aug-2018 16:16:08
Advertisements