Checking Enum Flags

If you using an enum that uses bit flags, here is an easy way to check to see if one or more if the values are set.


Public Shared Function CheckFlags(value As [Enum], flags As [Enum]) As Boolean
    If [Enum].GetUnderlyingType(value.[GetType]()) = GetType(ULong) Then
        Return (Convert.ToUInt64(value) And Convert.ToUInt64(flags)) <> 0
        Return (Convert.ToInt64(value) And Convert.ToInt64(flags)) <> 0
    End If
End Function


public static bool CheckFlags(Enum value, Enum flags)
    if (Enum.GetUnderlyingType(value.GetType()) == typeof(ulong)) {
        return (Convert.ToUInt64(value) & Convert.ToUInt64(flags)) != 0;
    else {
        return (Convert.ToInt64(value) & Convert.ToInt64(flags)) != 0;


CheckFlags(value, EnumModes.Save | EnumModes.Store)

Tip By: David McCarter


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s