O'Reilly logo

Microsoft Visual Studio 2015 Unleashed, Third Edition by Mike Snell, Lars Powers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating an Automatically Implemented Property

C# and Visual Basic allow for a simplified property declaration called auto-implemented properties. With this feature, you can declare a property without having to declare a local private field to back the property. Instead, the compiler does this for you. This can be useful when you do not need logic inside the property’s assessors.

For example, suppose you want to define the property Name on the Employee class. You can declare this property without setting a private field variable, as shown here.

C#

public string Name { get; set; }

VB

Public Property Name As String

Notice that there is no logic in the get or set statements. Instead, the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required