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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:39:40+00:00 2026-05-23T06:39:40+00:00

I think this question needs some code: private TypeValues GetEnumValues(Type enumType, string description) {

  • 0

I think this question needs some code:

private TypeValues GetEnumValues(Type enumType, string description)
        {
            TypeValues wtv = new TypeValues();
            wtv.TypeValueDescription = description;
            List<string> values = Enum.GetNames(enumType).ToList();
            foreach (string v in values)
            {
                //how to get the integer value of the enum value 'v' ?????
                wtv.TypeValues.Add(new TypeValue() { Code = v, Description = v });
            }
            return wtv;

        }

Call it like this:

GetEnumValues(typeof(AanhefType), "some name");

In the GetEnumValues function i have the values of the enum. So i iterate the values and i want to get the integer value of that enum value also.

So my values are ‘red’ and ‘green’, and i also want to get 0 and 1.

When i have the Enum in my function, i can create the enum value from the string and cast it to that enum and then cast it to an int, but in this case, i don’t have the enum itself, but only the type of the enum.

I tried passing in the actual enum as a parameter too, but i’m not allowed to pass an enum as a parameter.

So now i’m stuck…..

  • 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-23T06:39:41+00:00Added an answer on May 23, 2026 at 6:39 am
    private TypeValues GetEnumValues(Type enumType, string description)
            {
                TypeValues wtv = new TypeValues();
                wtv.TypeValueDescription = description;
                List<string> values = Enum.GetNames(enumType).ToList();
                foreach (string v in values)
                {
                    //how to get the integer value of the enum value 'v' ?????
    
                   int value = (int)Enum.Parse(enumType, v);
    
                    wtv.TypeValues.Add(new TypeValue() { Code = v, Description = v });
                }
                return wtv;
    
            }
    

    http://msdn.microsoft.com/en-us/library/essfb559.aspx

    Enum.Parse will take a Type and a String and return a reference to one of the enum values – which can then simply be cast to int.

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

Sidebar

Related Questions

I think this question is rather easy for you shell scripting monsters. I am
You may think this question is like this question asked on StackOverflow earlier. But
I think this is a multi-part question, so bear with me. Currently all of
I think the answer to this question is so obivous that noone has bothered
I think this must be a stupid question, but why do the results of
I asked this question before, Here however I think I presented the problem poorly,
This question is related to this one , though I think I was a
Although somewhat related to this question , I have what I think is a
I will preface this question by saying, I do not think it is solvable.
There is another recent Project Euler question but I think this is a bit

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.