Auto Implemented Properties

Published Monday, December 24, 2007 2:23 AM

C# 3 comes with a very nice feature (not undermining the power of lambda expressions and Linq), just this one shows how nice the language has evolved into

 

   1: class Employee
   2: {
   3:     public string firstName { get; set; }
   4: }

you see the previous code will act as a full blown property that maintains its instance value

internally the compiler creates a member and maintains the value for the property

and u can use it in the usual way

   1: var emp = new Employee();
   2: emp.firstName = "Amir";
   3: // next line will show a message box
   4: // with the value "Amir" shown :)
   5: // isn't that nice
   6: MessageBox.Show(emp.firstName);

 

Filed under: ,

Comments

# DotNetKicks.com said on Monday, December 24, 2007 2:33 AM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Leave a Comment

(required) 
(required) 
(optional)
(required)