[3.0/LINQ] Property Declartation
Not really a question just wanting to see how others feel about the new property declaration
Code:
public string Name
{
get;
set;
}
as opposed to
Code:
private string name;
public string Name
{
get
{
return name;
}
set
{
name=value;
}
}
I personally prefer the older syntax as within a class the idea of calling the property never seems right to me I always call the private field just wanting to hear other coders opinions :)
Re: [3.0/LINQ] Property Declartation
Our shop standard is unless you can get in the conference room in front of the the entire team and present an overwhelming case why you should use the private var we always call the property. You can probably guess we like the new syntax...
I'd much rather type
Code:
public string Name {get; set;}
fewer keystrokes, fewer opportunities to make a mistake.
This assumes of course that you have no need to do any coding in the getter or setter.
Re: [3.0/LINQ] Property Declartation
The problem with accessing the private variable within the class is that it bypasses any logic you add to the property getter or setter. If it is specifically desirable to by pass that logic then you should access the variable but otherwise you should always access the property. One of the reasons for properties is to allow you to change the implementation without changing the interface. If you were to change the property implementation at some point then every place you access the variable within the class would bypass the new logic.
Re: [3.0/LINQ] Property Declartation
That's awesome! I didn't know there was such a new feature in C# 2008! How cool is that? Way cool! So much less typing and confusion now and none of that, "should i access the variable or the propery stuff" and the, "should i put the private variable right next to the property or the other variables?"
Also, none of that think up crazy names for the private variables so when your application is converted to vb .net it will still work stuff.
Hah, this is way cool. :D
*very pleased*
Edit: Where do you find out about things like these? Is there a universal changelog avaiable somewhere on microsoft?
Re: [3.0/LINQ] Property Declartation
Quote:
Originally Posted by Fromethius
Also, none of that think up crazy names for the private variables so when your application is converted to vb .net it will still work stuff.
That was never a problem anyway. You just use "PropertyName" and "_propertyName" in both.
Re: [3.0/LINQ] Property Declartation
Quote:
Originally Posted by jmcilhinney
That was never a problem anyway. You just use "PropertyName" and "_propertyName" in both.
Hate that standard :)
Re: [3.0/LINQ] Property Declartation
The underscores cut me at night =(
Re: [3.0/LINQ] Property Declartation
The use of an underscore on variable names that provide a property value is unobtrusive and clear. That is something to strive for.