New language feature in C Sharp Orcas “Automatic Properties”
Posted on 3/10/2007 6:54:25
in #C Sharp
Hi,
In this post I will talk about the new features of C#3.0. These new features are really helpful to develop a product fast. Today when we code with C# we are used to code string and properties for it in the class. The code is simple
Private int _age;
Public int age
{
get{ return _age; }
set{ _age=value; }
}
Most of the time when we create a property we do not have any login inside it. Hence the question why should we use a property and not the public member directly? We have two benefits of using a property, first we can easily databind a property and second later if we want to put some validation later if required without affecting other classes that are using the object of this class.
The C# compiler has a new property called automatic properties. This lets us avoid having to manually declare a private field and write get set logic for it. So the example below will have the same effect as the example before. The compiler will automatically create the private field for us.
Public int age
{ get; set; }
Hope this helps Thanks Vikram
|
Posted on 3/31/2007 8:21:50
Oops! Really fantastic. Eagerly waiting to work on c# 3.0 then. Thanks for this.
|