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

  • SEARCH
  • Home
  • 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 7659781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:22:41+00:00 2026-05-31T13:22:41+00:00

I use a enum for describe different project states: [Flags] public enum ProjectStatus {

  • 0

I use a enum for describe different project states:

[Flags]
public enum ProjectStatus
{
   Undefined = 1 << 0,
   Closed = 1 << 1,
   Opened =1 << 2,
   ToMigrate = 1<<3 
}

Now, if I want to go from one state to another, I have to check if this is possible. For this I had the idea to extend my enum as follow:

[Flags]
public enum ProjectStatus
{
   Undefined = 1 << 0,
   Closed = 1 << 1,
   Opened = 1 << 2,
   ToMigrate = 1<<3,
   CanOpen = Opened | ToMigrate,
   CanClose = Opened,
   CanDelete = Closed | ToMigrate 
}

With this solution im able to check a state change:

if ((actualState & CanOpen) == CanOpen)
   {
      // open is allowed.
   }

My only problem is now, that e.g. CanClose and Opened have the same underlying value and CanClose == Opened is true.

So my question is, if someone knows an alternative way to handle this problem in a more elegant way. (maybe with two different enum types?)

thanks in advance!

  • 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-31T13:22:42+00:00Added an answer on May 31, 2026 at 1:22 pm

    Use distinct values, do not mess up them together, for example

    public enum ProjectStatus
    {
       Undefined = 1 << 0,
       Closed = 1 << 1,
       Opened = 1 << 2,
       ToMigrate = 1<<3      
    }
    

    And after check if the project can be closed in a function

    public bool CanClose(ProjectStatus status)
    {
        return (status & Opened) == Opened;
    }
    

    Something like this. You should definitely imrove this code, this is just an example.

    In other words, move desicional logic out of enum in a functions. In enum leave only a raw data.

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

Sidebar

Related Questions

If I use /clr:oldSyntax the following should work: public __value enum IceCreamFlavors { Vanilla,
I want to use an Enum value for the types of VaryByCustom parameters I
I want to use an Enum to represent some selection values. In the /src/groovy
I often use enums like public enum Side { Left, Top, Right, Bottom };
Can we use enum inside a switch? public enum Color { RED,BLUE,YELLOW } public
I'm creating a flags enumeration in C#, similar to the following: [Flags] public enum
Is it possible to use Enum in Android like this? public enum EventAction {
Here is the code I would like to use: public enum Days { Sat
I'm going to use enum flags for options to initialize my class. The enum
I want to use enum values in a <h:selectManyCheckbox> . The checkboxes get populated

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.