Enum types, FlagAttribute & Zero value: Enum types, FlagAttribute & Zero value:
We all know about Enums types and use them every single day. What is not that often used is to decorate the Enum type with the FlagsAttribute.
When an Enum type has the FlagsAttribute we can assign multiple values to it and thus combine multiple information into a single enum.
The enum values should be a power of two so that a bit set is achieved.
Here is a typical Enum type:
public enum OperationMode
{
/// <summary>
/// No operation mode
/// </summary>
None = 0,
/// <summary>
/// Standard operation mode
/// </summary>
Standard = 1,
/// <summary>
/// Accept bubble requests mode
/// </summary>
Parent = 2
}
In such scenario no values combination are possible. In the following scenario a default operation mode exists and combination is used:
[Flags]
public enum OperationMode
{
/// <summary>
/// Asynchronous operation mode
///...
[[ This is a content summary only. Visit my website for full links, other content, and more! Your comments are envited for your liking disliking and queries about the article]]
We all know about Enums types and use them every single day. What is not that often used is to decorate the Enum type with the FlagsAttribute.
When an Enum type has the FlagsAttribute we can assign multiple values to it and thus combine multiple information into a single enum.
The enum values should be a power of two so that a bit set is achieved.
Here is a typical Enum type:
public enum OperationMode
{
/// <summary>
/// No operation mode
/// </summary>
None = 0,
/// <summary>
/// Standard operation mode
/// </summary>
Standard = 1,
/// <summary>
/// Accept bubble requests mode
/// </summary>
Parent = 2
}
In such scenario no values combination are possible. In the following scenario a default operation mode exists and combination is used:
[Flags]
public enum OperationMode
{
/// <summary>
/// Asynchronous operation mode
///...
[[ This is a content summary only. Visit my website for full links, other content, and more! Your comments are envited for your liking disliking and queries about the article]]
Comments
Post a Comment