You don't need to access the hidden variable for MyVar.
Just use the public one from inside or outside of your class.
If you need to restrict access to it, either make it private or protected.
Don't worry about it.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
I understand what you are asking, but you should realize that {get;set;} accessor methods are the shortcuts to the longer version. You can use the longer version if you need more direct control over what is delivered or you can intercept part of the set or the get.
http://msdn.microsoft.com/en-us/library/aa287786(v=VS.71).aspx
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
When you use the short version
public int MyVar { get; set; }
The C# compiler is smart enough to work this syntax out to the full version. With a sectretly generated field variable.
You use it for simple properties likecolor etc. You just have to set or get a color. Suppose you have to make 100 color properties. Saves you a lot of typing! Let the compiler do this work for you!
On the other hand if you have a property like LoanAmount you have to use the normal,long version, because you probably want to add some taxes, do a check if the right person is logged in or whatever.
Hope this clears things up. ;)
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661