In C# I have seen enums used in a flag format before. Such as with the Regex object.
Regex regex = new Regex("expression", RegexOptions.Something | RegexOptions.SomethingElse);
If I have a custom enum:
enum DisplayType
{
Normal,
Inverted,
Italics,
Bold
}
How would i format a method to accept multiple enums for one argument such as the syntax for Regex? i.e SomeMethod(DisplayType.Normal | DisplayType.Italics);.
Use the
FlagsAttribute. The MSDN documentation explains everything. No point repeating it here.For your example, you’d say: