Profile picture Schedule a Meeting
c a n d l a n d . n e t

Using flags in c#

Dusty Candland | |

Some notes about using enums as flags in C#. Use the FlagsAttribute on you enum. Have a None option set to 0. Have the first option start at 1, and each next value should be 2 times the previous one (I wonder what that pattern is called). Something like:

[Flags]
public enum PropertyOptions
{

None = 0,
IgnoreProperty = 1,
DisplayName = 2

}

Checking if a flag is set is done using the following syntax:

bool isIgnoreSet = (_options&PropertyOptions.IgnoreProperty) == PropertyOptions.IgnoreProperty;

Guidelines: http://msdn2.microsoft.com/en-us/library/ms229062.aspx

Using The Enum: http://dotnet.org.za/kevint/pages/Flags.aspx

Webmentions

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: