Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6759409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:56:09+00:00 2026-05-26T13:56:09+00:00

The system have a plain enum like this, public enum SomeEnum : short {

  • 0

The system have a plain enum like this,

public enum SomeEnum : short
{ 
    Ok = 0,
    Missing = 17,
};

This enum are now into a situation where I need to mask some more information into it without change the appearence of the existing enum values. The enum will got some new values,

[Flags]
public enum SomeEnum : short
{ 
    Ok = 0,
    Missing = 17,
    Blocking = 18, // Values could be anything
    Low  = 19,     // Values could be anything
};

I was afraid there could be problem to the current enum usage. It appears that I’m right, but I hope i’m proved wrong with your help. The usage until today are built around SomeEnum.Ok. Also tomorrow, but the Ok need additional info. I need to mask the enum values without affect it’s current behavior, which could came from any common reference;

someEnumVariable.ToString()
(int)someEnumVariable
someVar = SomeEnum.Ok
Enum.Parse(typeOf(SomeEnum), someString)

If I flag the enum with

var test = (SomeEnum.Ok | SomeEnum.Blocking);
Both flags can be founded i.e. test.HasFlags(SomeEnum.Ok) or test.HasFlags(SomeEnum.Blocking) but the enum represents as SomeEnum.Blocking, which aren’t possible.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:56:09+00:00Added an answer on May 26, 2026 at 1:56 pm

    Because the value of SomeEnum.OK is 0, calling HasFlag(SomeEnum.OK) will always return true. When you mask enums together, the process relies on the fact that the sum of any combination of enum values will be unique. Typically you would set these up starting using values of 2^0, 2^1, 2^2, etc. For example:

    [Flags]
    public enum SomeEnum : short
    { 
        Ok = 1,
        Missing = 2,
        Blocking = 4, // Values could be anything
        Low  = 8,     // Values could be anything
    }
    

    If you want to mask the values together, you’ll have to use the Flags attribute. If you can’t refactor and change the value of SomeEnum.OK, then you may have to rely on passing in a SomeEnum[], rather than a single masked SomeEnum value.

    EDIT
    Just a quick note on masking the values together using the enum defined above. Take the following code:

    var t1 = (int)(SomeEnum.OK | SomeEnum.Missing);       //t1 = 1 + 2 = 3
    var t2 = (int)(SomeEnum.Missing | SomeEnum.Blocking); //t2 = 2 + 4 = 6
    var t3 = (int)(SomeEnum.OK | SomeEnum.Low);           //t3 = 1 + 8 = 9
    var t4 = (int)SomeEnum.OK;                            //t4 = 1
    var s1 = (SomeEnum.Ok).ToString();                    //s1 = "Ok"
    var s2 = (SomeEnum.Ok | SomeEnum.Missing).ToString(); //s2 = "Ok, Missing"
    

    When these items are OR’ed together, .NET just adds the values together to produce a new, unique value that represents the combination of the OR’ed items. Using enum values that are powers of 2 ensures that the combinations will always be unique.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASPX based component which I'd need to inlude into a plain
i have System.Data.DataRows with several fields, most of them just plain types like int,
I have a custom handler like this, public class Handler : IHttpHandler { public
I am programming system in C and I would like to draw rectangles into
I'm using velocity templates to generated plain-text emails for a notification system. I have
I'm working on a help system in HTML, and I'd like to have links
I want to create a system UIBarButton, but I want it to have plain
What is the best way to have a virtual operating system have a static
We're using SQL Server 2005 in a project. The users of the system have
We have system here that uses Java JNI to call a function in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.