Say, you originally declared a variable: (let's walk this through in C#)
private bool someValue= false;...
In some codes, we often see ...
public void toggleSomeValue(bool b){this.someValue = b;}
However, the above is not exactly toggling. It's more like setting someValue to some arbitrary value that you demand.
It should be re-written as:
public void toggleSomeValue(){this.someValue = !this.someValue;}
orpublic void toggle(bool someValue)
// if someValue is declared as class variables{someValue = !someValue;}orpublic bool toggle(bool someValue)
// you actually don't need this, but FYI.{return !someValue;}
Then, down the page, you would have a function that makes use of the toggled value
public void doSomethingBasedOnSomeValue(){if(this.someValue)//do thiselse//do thattoggleSomeValue(); //or toggle(this.someValue);}
-my tuppence worth
No comments:
Post a Comment