C# Automatic Properties in Use during Visual Studio 2008 Development
by David Hayden ( Microsoft MVP C# ), Filed: C# 3.0 Features
I talked about C# Automatic Properties quite some time ago in the following post:
Automatically Implemented Properties - Visual Studio Orcas C# Compiler - C# 3.0
and it still feels out a place using this new feature in C# 3.0 in an actual development project using Visual Studio 2008.
C# Automatic Properties allows one to declare properties in classes using a style that you would normally use in an Interface:
public class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
public string EmailAddress { get; set; }
}
Notice you don't need to declare any fields associated with the properties. The C# 3.0 compiler handles all of that for you.
The only drawback to this new style of declaring properties in your classes is that you don't have access to the underlying field used by the property, so obviously you wouldn't use it in those cases when you do need access to the field.
Automatic Properties is just one of an interesting list of new C# 3.0 Enhancements.
Source: David Hayden ( Microsoft MVP C# )
Filed: C# 3.0 Features