Generic extension method to see if an enum contains a flag

前端 未结 8 1114
闹比i
闹比i 2021-02-01 01:56

Considering this:

[Flags]
public enum MyEnum {
    One = 1,
    Two = 2,
    Four = 4,
    Eight = 8
}

public static class FlagsHelper
{
    public static bool          


        
8条回答
  •  执念已碎
    2021-02-01 02:26

    Not sure if you're using .NET 4.0 or not, but it comes with the static method Enum.HasFlags().

    -- Code Removed (the accepted solution has it already) --

提交回复
热议问题