Automatic Properties
-
Hi, If you use an automatic property and want to reference it within the same class I assume you would specify the property but if you had another property within the same class that required validation you would reference the field. Don't you think this is messy code? <code> private string _firstName; public string FirstName { get { return _firstName; } set { _firstName = value; } } public string LastName { get; set; } public void Foo() { string test = _firstName + LastName; } </code>
-
Hi, If you use an automatic property and want to reference it within the same class I assume you would specify the property but if you had another property within the same class that required validation you would reference the field. Don't you think this is messy code? <code> private string _firstName; public string FirstName { get { return _firstName; } set { _firstName = value; } } public string LastName { get; set; } public void Foo() { string test = _firstName + LastName; } </code>
I think automatic properties are ugly to start with.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Hi, If you use an automatic property and want to reference it within the same class I assume you would specify the property but if you had another property within the same class that required validation you would reference the field. Don't you think this is messy code? <code> private string _firstName; public string FirstName { get { return _firstName; } set { _firstName = value; } } public string LastName { get; set; } public void Foo() { string test = _firstName + LastName; } </code>
Why not like this?
public void Foo() { string test = FirstName + LastName; }
The fact that there is a field doesn't mean you have to use it... Robert -
Why not like this?
public void Foo() { string test = FirstName + LastName; }
The fact that there is a field doesn't mean you have to use it... Robert -
The Microsoft Coding Guidelines says you should use fields internally within a class. I could be wrong?!?!?
They are guidelines. Not the law. Judge Dredd isn't going to pay a visit because of this.
Deja View - the feeling that you've seen this post before.
-
They are guidelines. Not the law. Judge Dredd isn't going to pay a visit because of this.
Deja View - the feeling that you've seen this post before.
He will if you name all your controls TextBox1 and ComboBox1 though. Okay, I can dream...
-
He will if you name all your controls TextBox1 and ComboBox1 though. Okay, I can dream...
He mightn't, but I will visit with the wet towel of vengeance ready to whip his sorry ass.
Deja View - the feeling that you've seen this post before.
-
He will if you name all your controls TextBox1 and ComboBox1 though. Okay, I can dream...
-
The Microsoft Coding Guidelines says you should use fields internally within a class. I could be wrong?!?!?
Those guidelines were probably written before automatic properties were introduced. I made just a suggestion. You said it looked ugly... :laugh: Robert