What is the best way to set my boolean properties based on an int counter property?
So, lets say I have 10 boolean properties
public bool IsBool1 {get;set;}
....
public bool IsBool10 {get;set;}
and an int counter (which can never have a value greater than 10)
public int Counter {get;set;}
Finally, I have a method which sets the flags
private void SetFlagsByCounter(int counter)
{
if (counter >= 1) { IsBool1 = true; }
.....
if (counter >= 10) { IsBool10 = true; }
}
Is there a better way to set the flags instead of iterating the counter?
Do you actually need to have the 10 auto-properties? Could you have 10 properties which just return a value based on the counter? (Do you even need 10 properties in the first place?)
For example:
Note that this differs from your original in 3 ways:
SetFlagsByCountermethod, just the propertySetFlagsByCounter(10)and thenSetFlagsByCounter(1), then IsBool5 (etc) would still return true, because you never cleared the flags.SetFlagsByCounterdidn’t use (or change) theCounterproperty at all, in the code shown.If you could give more context, it would be easier to help you.