c# - Having multiple properties incrementing one variable. Simple check of its value? -
i have 10 properties when each set increments value of variable value
. when value of value
10, app end. seems awkward write same condition each of them this:
int value=0; int { set { a=value; value++; if(value>10) ... //check here } } int b { set { b=value; value++; if(value>10) //check here again } }
how can simplify checking value?
private int counter; private int b; private int a; public int { set { counter++; = value; checkcounter(); } } public int b { set { counter++; b = value; checkcounter(); } } public void checkcounter() { if (counter>10) { //do } }
or make counter property..
private int counter { set { counter = value; checkcounter(); } { return counter; } }
and use when incrementing..
counter++;
Comments
Post a Comment