C# Language Properties Default Values for Properties

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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";
  }


Got any C# Language Question?