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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:05:20+00:00 2026-06-10T15:05:20+00:00

I have an enumeration that is a member variable of an object. I don’t

  • 0

I have an enumeration that is a member variable of an object. I don’t know the enumeration’s exact type, only that it is derived from System.Enum. I want to set the enumeration’s underlying numeric value. In other words:

Enum e;
// ...
e = 42;  // Doesn't comple

Is this possible? Can it be done with reflection?

Edit 1: The enum is part of a larger data structure, so creating a new value using Enum.ToObject() is not suitable.

Edit 2: Clarified that the enum is a member variable of an object.

Edit 3: Since a few commenters have asked for more context, heres a summary: I have some general-purpose code that is supposed to associate UI controls (text boxes, etc) with corresponding fields in an object data model. When the UI changes the model is updated, and vice-versa. I was looking at extending this to map between combo boxes and enumerations; where the enum would be set to the index of the selected combo entry. Setting the selected item from the enum’s underlying value is trivial, but the reverse of this is where the problem occurs. I was fairly sure that this wasn’t going to be possible, but thought it was worth asking.

  • 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-10T15:05:21+00:00Added an answer on June 10, 2026 at 3:05 pm

    You need to know the enum’s Type at runtime, even if you don’t know it at compile-time – bacause Enum is a boxed value, and in order to box something you need to have access to the type (so that .GetType() returns the right thing); for example, doing this at runtime:

    public Enum GetEnumValue(Type type) {
        return (Enum)Enum.ToObject(type, 42);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed that some enumerations have None as a enumeration member. For example what
I have an enumeration that I am trying to initialize from a long value
Does Perl have an enumeration type that adheres to best practices , or maybe
So, I have an enumeration that is as follows: +---------+ |TypeCours| | Enum |
I have registered an enumeration type ClefType within my header file - this enum
I have an enumeration that I want to use in pattern matches in an
In my compiler project, I have an enumeration that goes like enum Result {
I need to create an enumeration that I will need to initialize from a
I have an enumeration that looks like the following public enum MyEnum { A,
Possible Duplicate: How to enumerate an enum? Suppose that i have an enumeration like

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.