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 6612719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:07:54+00:00 2026-05-25T20:07:54+00:00

I have an enumeration: public enum SomeEnum { A = 2, B = 4,

  • 0

I have an enumeration:

public enum SomeEnum
{
  A = 2,
  B = 4,
  C = 8
  D = 16 
}

SomeEnum e1 = SomeEnum.A | SomeEnum.B

Now I want to have a List of enum values, so e1 would be:

2, 4

So I have:

List<int> list = new List<int>();

foreach(SomeEnum se in Enum.GetValues(typeof(SomeEnum)))
{

  if(.....)
  {
     list.Add( (int)se );
  }


}

I need help with the if statement above.

Update

How can I build a list of ints representing the flags set in the enum e1?

  • 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-25T20:07:55+00:00Added an answer on May 25, 2026 at 8:07 pm

    Do you want to add the value if it’s in e1?

    Then you can use the HasFlag method in .NET 4.

    if(e1.HasFlag(se))
    {
        list.Add( (int)se );
    }
    

    If you’re not using .net the equivilant is e1 & se == se

    Also by convention you should mark your enum with the FlagsAttribute and it should be in plural form (SomeEnums)

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

Sidebar

Related Questions

I have the following enumeration: public enum AuthenticationMethod { FORMS = 1, WINDOWSAUTHENTICATION =
I have an enumeration for my Things like so: public enum Things { OneThing,
I have one class that declares an enumeration type as: public enum HOME_LOAN_TERMS {FIFTEEN_YEAR,
I have enumeration like this: public enum Configuration { XML(1), XSLT(10), TXT(100), HTML(2), DB(20);
I have an enumeration that looks like the following public enum MyEnum { A,
I have an enumeration with [Flag] attribute set on it. [Flags] public enum PageTags
I have the following enumeration of membership roles: public enum RoleName { RegisteredUser, Moderator,
I have an enumeration: public enum MyColours { Red, Green, Blue, Yellow, Fuchsia, Aqua,
Assume i have an enumeration : namespace System.Windows.Forms { public enum DialogResult { None,
I have a c# enumeration that looks like this: public enum EthernetLinkSpeed { [Description(10BASE-T)]

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.