I’m looking for a way to pass different options as a parameter to a method.
Let’s assume that a user can choose any or all of 6 options or any subset of them.
So he could choose all options, only option 1, 2 & 4, only option 1, 3, 5 & 6 etc…
How do I pass this around effectively?
I was thinking of using an Enum since you can do bitwise additions, but I’m missing the next pieces of the puzzle to go from there:
Could my method then become something like:
public void Foo(byte selectedOptions)
{
// How do I check whether an option has been selected??
if (selectedOptions >= Option.Whatever) DoThis();
}
So you see I’m kind of stuck on the bitwise comparisons and I wonder if this is even the right way…
What I don’t want to do is:
public void Foo(bool option1Selected, bool option2Selected, etc...);
Ideas?
Go with enum Flags
For selecting multiple options use bitwise or
To check if a flag is selected use bitwise and