What does the [Flags] Enum Attribute mean in C#?

前端 未结 13 2286
慢半拍i
慢半拍i 2020-11-21 04:21

From time to time I see an enum like the following:

[Flags]
public enum Options 
{
    None    = 0,
    Option1 = 1,
    Option2 = 2,
    Option3 = 4,
    Op         


        
13条回答
  •  失恋的感觉
    2020-11-21 05:07

    Flags allow you to use bitmasking inside your enumeration. This allows you to combine enumeration values, while retaining which ones are specified.

    [Flags]
    public enum DashboardItemPresentationProperties : long
    {
        None = 0,
        HideCollapse = 1,
        HideDelete = 2,
        HideEdit = 4,
        HideOpenInNewWindow = 8,
        HideResetSource = 16,
        HideMenu = 32
    }
    

提交回复
热议问题