"Herve Bocuse" <gd******@gmail.com> wrote in message
news:cp**********@dns3.cae.ca...
Hi,
I'm just wondering what are the guidelines for using a Property or a pair
of
get/set methods related to a member variable ?
What do yu guys do ?
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