How to use Enum with additional options (All, None)

前端 未结 3 1523
栀梦
栀梦 2021-01-05 12:38

I have an enum, which:

  • is included in my class as a property
  • it represents some values from a database table (a couple of types)
  • it is displa
3条回答
  •  清酒与你
    2021-01-05 12:44

    IMHO, it's best to add an 'All' value to your enum like so:

    enum SampleEnum 
    {
        Value1 = 1,
        Value2 = 2,
        Value3 = 4,
        All = Value1 | Value2 | Value3 
    }
    

    This way, you won't have to care about the displayed items in your combobox, and you can react to the selection of that value in your code, if that should be necessary...

提交回复
热议问题