IsSet

public static bool IsSet(this Enum input, Enum matchTo)
{
    return (Convert.ToUInt32(input) & Convert.ToUInt32(matchTo)) != 0;
}
Example:
MyEnum tester = MyEnum.FlagA | MyEnum.FlagB;

if(tester.IsSet(MyEnum.FlagA))

Description

I did not write this I just found it very useful, check http://stackoverflow.com/questions/7244 for original post.

Details

  • Author: JA
  • Submitted on: 9/8/2009 4:04:17 PM
  • Language: C#
  • Type: System.Enum
  • Views: 2880

Double click on the code to select all.

 

;