Reputation: 3647
I'd like to create some custom data types, but I don't think I'm asking the right question(s).
There are "compound Boolean" values used throughout .NET, and I want to design some of my own. I've been using a series of Boolean variables, which works, but just isn't the same.
Examples from .NET include: Color.Black Alignment.Centered [fontProperties].Bold* *I forget the actual name, but you get the idea
I want to make something like this:
ColorSortQualities
Once that's been declared, I could do this: if(searchOptions.ColorSortQualities == DistinguishColor) [do stuff]
What is this called?
Thanks!
Upvotes: 1
Views: 1011
Reputation: 284927
I think you want a enumeration with the [Flags]
attribute.
[Flags]
enum ColorSortQualities
{
None = 0x0,
DistinguishColor = 0x1,
DistinguishNumberOfColors = 0x2,
DistinguishColorPattern = 0x4
}
This will let the caller specify any combination of those, each of which will be implemented as a bit flag. Note that this will allow 32 options, because int is a 32-bit quantity.
Your condition code would look like:
if((searchOptions & ColorSortQualities.DistinguishColor) == ColorSortQualities.DistinguishColor)
If that isn't what you mean by "series of Boolean variables", please clarify.
Upvotes: 3
Reputation: 838786
It's called an enumeration and in C# you use the keyword enum
.
Upvotes: 4
Reputation: 5123
Use an enum:
enum ColorSortQualities
{
None,
DistinguishColor,
DistinguishNumberOfColors,
DistinguishColorPattern
};
Upvotes: 5