|
-
Dec 4th, 2007, 09:52 AM
#1
Thread Starter
Fanatic Member
[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
Useful Links
.Net
#Develop, GhostDoc, CodeKeep , be.PINVOKE, Good Code Snippet Site
Krypton Toolkit, XPCC / XP Common Controls, QSS Windows Forms Components
VB.COM
VB.Classic Help File, MB Controls, MZTools, ADO Stored Procedure Generator add-in,
-
Dec 4th, 2007, 01:35 PM
#2
Hyperactive Member
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.
Last edited by VBGuy; Dec 4th, 2007 at 01:39 PM.
-
Dec 4th, 2007, 06:27 PM
#3
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.
-
Dec 4th, 2007, 07:49 PM
#4
Frenzied Member
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. 
*very pleased*
Edit: Where do you find out about things like these? Is there a universal changelog avaiable somewhere on microsoft?
Last edited by Fromethius; Dec 4th, 2007 at 07:50 PM.
Reason: Thought of something else to say.
-
Dec 4th, 2007, 08:50 PM
#5
Re: [3.0/LINQ] Property Declartation
 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.
-
Dec 5th, 2007, 01:25 AM
#6
Re: [3.0/LINQ] Property Declartation
 Originally Posted by jmcilhinney
That was never a problem anyway. You just use "PropertyName" and "_propertyName" in both.
Hate that standard
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Dec 5th, 2007, 06:09 AM
#7
Frenzied Member
Re: [3.0/LINQ] Property Declartation
The underscores cut me at night =(
-
Dec 5th, 2007, 06:01 PM
#8
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|