I wouldn't say that you should never GetX or SetX. If the setting or
getting of the property is a significant event (it would cause a long time
to execute, sets much more than just the value), then it is more
appropriate to have that in a method, then just a property.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
David Browne said:
Never getX setX. Either properties or public member variables. I know
many people disagree, but I use public member variables alot on stuff
that is not visible across solutions. Public member variables should be
named just like properties, so if you later encapsulate the member
variable, client code won't break (although it will need to be
recompiled). My rule of thumb for public member variables is that they
are OK instead of properties so long as all the client classes get
recompiled whenever the class containing the member variable does.
I use initial-caps camel casing for all public data members, and
initial-lower camel casing for all private data members.
I also name constructor arguments after the public data member they
represent (possibly using this. in the constructor body to distinguish
the argument from the member).
class Foo1
{
public Foo1(int MyInt)
{
this.MyInt = MyInt;
}
public int MyInt;
}
or
class Foo2
{
public Foo2(int MyInt)
{
myInt = MyInt;
}
int myInt;
int MyInt
{
get
{
return myInt;
}
set
{
myInt = value;
}
}
}
David