auto implemented properties

Monday, December 24, 2007 4:23 AM | Leave a reply »

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);


Comments

  1. Gravatar Anonymous says:

    Re : # 

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


Leave a Reply



 

Please add 2 and 2 and type the answer here: