I have been trying to wrap my head around the finer points of this today.
Essentially I have fallen in love with this format for booleans:
Class {
public static bool myBool {set; get;}
private static void Method()
{
if (!myBool)
{
myBool = !myBool;
// stuff that needs to be done
}
}
}
Obvious things like do not use a public when a private will work and scoping properly applies. But when is this a best practice vs using a simpler:
Class {
bool myBool = true;
private static void Method()
{
if (!myBool)
{
myBool = !myBool;
// stuff that needs to be done
}
}
}
Or do I have this backwards completely?
I understand that by using the format public static bool myBool {set; get;}
I doing the following:
public static bool myBool
{
get
{
return myBool;
}
set
{
myBool = valuePassedIn;
}
}
I feel like the first method is the best approach, but I have no idea why I think this. Is there a best from these choices? Am I doing something horribly wrong, or all three methods equivalent?