Default Values for Properties C# with Example



Default Values for Properties C# with Example

Setting a default value can be done by using Initializers (C#6) 
public class Name 
{ 
public string First { get; set; } = "James"; 
public string Last { get; set; } = "Smith"; 
} 
If it is read only you can return values like this: 
public class Name 
{ 
public string First => "James"; 
public string Last => "Smith"; 
 

} 

0 Comment's

Comment Form

Submit Comment