.NET Tips and Tricks

Blog archive

What's New in C# 6.0: Initialize Properties Just Like Fields

Auto-implemented properties let you define a property in a single line of code:

  public string LastName { get; set; }

In C# 6.0, you can also initialize that property to some constant value in the same statement, like this:

  public string LastName { get; set; } = "Vogel";

Yes, it's that simple.

Posted by Peter Vogel on 04/21/2015


comments powered by Disqus

Featured

Subscribe on YouTube