You must Sign In to post a response.
  • Category: .NET

    How to change enumeration to an array of constants

    Hi All,
    I have following enumeration which I need to convert to array of constants.
    Can someone please give me any clue?
    public enum PermissionsEnum: long
    {
    Permission1 = -1,
    Permission2 = 1,
    Permission3 = 2,
    Permission4 = 4,
    Permission5 = 8,
    Permission6 = 16
    }

    Thanks
  • #769411
    Do you want to store both the key and its respective values or just the values defined for the permission? If you want to define only the values, you can create a readonly int array with values as shown below:
    public static readonly int[] Permissions= {-1,1,2,4,8,16 };

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net


  • Sign In to post your comments