C# 3.0 Automatic Properties

March 12th, 2009 Leave a comment Go to comments

OK, so better later than never! Somehow I missed the automatic properties feature of C# 3.0, and just discovered it while I was reading up on something unrelated. It’s a nice feature of C# 3.0 that saves you a few key strokes hence enhances developer productivity as well as allows for more clear and concise code.

Using this new feature, instead of defining private variables and creating explicit getters and setters, you can create properties like this:

public class Employee
{
   public string ID { get; set; }
   public string LastName { get; set; }
   public string FirstName { get; set; }
}

  1. No comments yet.
  1. No trackbacks yet.
 

Comment moderation is enabled. Your comment may take some time to appear.