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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:16:37+00:00 2026-06-04T13:16:37+00:00

My question is how can I get values of enum variable? Please look at

  • 0

My question is how can I get values of enum variable?

enter image description here
Please look at the attached screenshot… “hatas” is a flag-enum. And I want to
get “HasError” – “NameOrDisplayNameTooShort” errors to show them.

using System;

namespace CampaignManager.Enums
{
    [Flags]
    public enum CampaignCreaterUpdaterErrorMessage
    {
        NoError = 0,
        HasError = 1,
        NameOrDisplaynameTooShort = 2,
        InvalidFirstName = 3,
    }
}

I tried simply;

Messagebox.Show(hatas);  // it's showing InvalidFirstName somehow...

Thank you very much for any help…

  • 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-06-04T13:16:39+00:00Added an answer on June 4, 2026 at 1:16 pm

    First thing: If you want to use the FlagsAttribute on your enum you need to define the values in powers of two like this:

    [Flags]
    public enum CampaignCreaterUpdaterErrorMessage
    {
        NoError = 0,
        HasError = 1,
        NameOrDisplaynameTooShort = 2,
        InvalidFirstName = 4,
    }
    

    To get parts of a flagged enum, try something like:

        var hatas = CampaignCreaterUpdaterErrorMessage.HasError | CampaignCreaterUpdaterErrorMessage.NameOrDisplaynameTooShort;
        var x = (int)hatas;
    
        for (int i=0; i<Enum.GetNames(typeof(CampaignCreaterUpdaterErrorMessage)).Length; i++)
        {
            int z = 1 << i; // create bit mask
    
            if ((x & z) == z) // test mask against flags enum
            {
                Console.WriteLine(((CampaignCreaterUpdaterErrorMessage)z).ToString());
            }
        }
    

    For getting the underlying value try casting:

    Messagebox.Show(((int)hatas)ToString());
    

    In your example, ToString is getting called by default against the CampaignCreaterUpdaterErrorMessage enum which return the string representation of the enum.

    By casting to an int, the underlying default type for enums, you get ToString on the integer value.

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

Sidebar

Related Questions

My question is, that how can I get the node in witch I want
HTML Javascript question to get the selected value of a input-select I can use
Question: I can get the SQL Server database language by querying: SELECT @@language And
Reading this article http://support.microsoft.com/kb/813878 I have a question: Where can I get ipseccmd.exe for
this is a bit of a newbie question but hoping I can get some
I have what I think is a simple question but I can't get it
Sorry for the double post, I will update this question if I can't get
My question is, how can I get text from header in javascript? So if
Referring to this question , how can i get the current page size in
I have a question about JSF and GET http request. How can I get

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.