.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 at 2:19 PM


comments powered by Disqus
Upcoming Events

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.