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!!!
Comments
Anonymous
March 23, 2007
PingBack from http://paanis.wordpress.com/2007/03/24/c-30-new-features/Anonymous
March 23, 2007
But what are the benefits then, compared with a public variable (which one shouldn't do, sure)? The benefits of a property was to me to do MORE than just assigning a variable or returning a variables value. This new feature seems to force just the opposite?!?Anonymous
March 23, 2007
Just like Uwe I wonder if can later on change the storage of the data. What if my property later on changes to be the computation of some other values or what if setting that property should also change other parts of that class? On a first look this feature seems to make properties easy in the first place but harder for changing the class later on.Anonymous
March 24, 2007
La nueva versión de C# trae una característica que se conoce como propiedades automáticas, que no esAnonymous
March 24, 2007
Two places that you may need a property and not a field are when you implement an interface that defines a property and when you make a dll for others to use where it is not convienient to change from a field to a property later.Anonymous
March 26, 2007
Hello everyone, Automatic property is just another way of declaring it. You can use the good old property declaration style if your property contains complex calculation and trick. For C# 3.0 what this kind of property declaration does is that CLR interns defines a property with the syntax something like private int _XYZ; public int CustID { get { return _XYZ; } set { _XYZ = value; } } C# 3.0 enables us to increase the level of abstraction. I will come up with the answer in more details in next entry. WrijuAnonymous
March 26, 2007
The comment has been removedAnonymous
March 26, 2007
Hi Szurgot, Thanks for the feedback. Yes you are correct. This is just another way of declaring Property. WrijuAnonymous
December 14, 2007
With this exciting release of .NET Framework 3.5 I have been exploring its magic and sharing the findingAnonymous
January 28, 2008
link http://susanneguitierr.mysite.com/ page http wwwAnonymous
January 28, 2008
website http://latoniawarford.00me.com/ website home domainAnonymous
January 28, 2008
page http://genevaokelly.jokestan.cc/ domain domain websiteAnonymous
July 12, 2008
What is valium used for. Valium statistics. Valium picture. Valium.