Switch on Enum (with Flags attribute) without declaring every possible combination?

后端 未结 9 2024
忘掉有多难
忘掉有多难 2021-01-31 14:15

how do i switch on an enum which have the flags attribute set (or more precisely is used for bit operations) ?

I want to be able to hit all cases in a switch that matche

9条回答
  •  一整个雨季
    2021-01-31 15:01

    Just use HasFlag

    if(theCheckType.HasFlag(CheckType.Form)) DoSomething(...);
    if(theCheckType.HasFlag(CheckType.QueryString)) DoSomethingElse(...);
    if(theCheckType.HasFlag(CheckType.TempData)) DoWhatever(...);
    

提交回复
热议问题