Consider the following City class:
public class City
{
public string name { get; set; }
public int CountryCode { get; set; }
}
If we were to initialize it in C#, our code would be something like this:
City myCity = new City();
myCity.Name = "Oporto";
myCity.CountryCode = 351;
Now in C# 3.0, life is easier in class property initialization. In a scenario of a class with 50 properties it might be troublesome if you were to consider a constructor definition method, but now you can declaratively set any number of properties on class initialization, like this:
City myNewCity = new City() { Name = "Oporto", CountryCode = 351};
Now...
In C# 3.0 things have changed in what comes to property declaration structure and initializing. Now, instead of the typical private variable model:
private List<string> _menuItems;
public List<string> MenuItems
{
get {return _menuItems;}
set { _menuItems = value; }
}
You can now write:
public List<string> MenuItems { get; set; }
Neat huh? Visual Studio 2008 code snipplets (right mouse click -> Insert Code Snipplet -> Visua C# -> prop) are already templated to this format.