Monday, July 28, 2008

C# Auto Properties

I learned a short-cut today for properties.  They're called auto properties.  Properties in C# are simple getters and setters in Java.  auto properties make writing properties even easier.

Several times a day I have typed something similar to:

 public string Country

{

  get { return country; }

  set { country = value; }

}

I've been using Resharper for several months now, but just noticed today that it recommended that I write a property this way:

 public string Country { get; set; }