|
-
August 21st, 2008, 08:27 PM
#1
Why get/set?
Hi everyone,
I wanted some opinions on something i really don't understand the need for. so i was looking at vs2008's auto-implemented properties, and i don't understand the necessity for them. Then, I started thinking about why even have get/set properties at all if you are just giving public access to a private variable. i understand if you are making it read only, or protecting it, but I don't get a completely public implementation with no logic. Unless the idea is just to maintain style.
So, why have
Code:
private int _foo
public int foo
{
get
{
return _foo;
}
set
{
_foo = value;
}
}
When you could just have
public int _foo
and directly access the class number? My reference books say I should do this, and I never really questioned it, but the more I think about it, I just don't get it. Thanks for any opinions.
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
|