C# 3.0 Features: Automatic Property
I am super excited with the Orcas March 2007 CTP release. I was doing the hands on with the C# and LINQ and as you know C# 3.0 comes with a lot of new things which increases the level of abstraction for the developer. We now write less and do more. As I often have mentioned in my previous entries and presentations with Microsoft Partner that now have think more on why not on how. I remember the day when I first learned the Property. I used to scratch my head on what to do with get or set. I probably started it now as we have snippet for property. Anyways in conventional way we declare property in a class like
publicclassCustomer
{
public Customer() { }
privateint _CustID;
publicint CustID
{
get { return _CustID; }
set { _CustID = value ; }
}
}
Now C# 3.0 suggests us not to invest so much. Rather than using property like
privateint _CustID;
publicint CustID
{
get { return _CustID; }
set { _CustID = value ; }
}
We can declare property like
publicint CustID
{
get ;
set ;
}
No more private variable or = or value etc required. This is Automatic property in C# 3.0.
Namoskar!!!