Skip to main content

Enum types, FlagAttribute & Zero value

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]]

Comments

Popular posts from this blog

Authenticate User on Active Directory

What is Active Directory A directory service from Microsoft that is a part of Windows 2000. It is an implementation of Internet standard directory and naming protocols that uses a database engine for transactional support, and also supports a variety of application programming interface standards. System.DirectoryServices Namespace The System.DirectoryServices namespace provides easy access to Active Directory Domain Services from managed code. The namespace contains two component classes, DirectoryEntry and DirectorySearcher, which use the Active Directory Services Interfaces (ADSI) technology. ADSI is the set of interfaces that Microsoft provides as a flexible tool for working with a variety of network providers. ADSI gives the administrator the ability to locate and manage resources on a network with relative ease, regardless of the size of the network. System.DirectoryServices.ActiveDirecto...