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

The Archive Base Latest Questions

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

I got the following enum: public enum detallistaDocumentStatus { /// <remarks/> ORIGINAL, /// <remarks/>

  • 0

I got the following enum:

 public enum detallistaDocumentStatus {

    /// <remarks/>
    ORIGINAL,

    /// <remarks/>
    COPY,

    /// <remarks/>
    REEMPLAZA,

    /// <remarks/>
    DELETE,
}

then I got a class property of type detallistaDocumentStatus:

 public detallistaDocumentStatus documentStatus {
        get {
            return this.documentStatusField;
        }
        set {
            this.documentStatusField = value;
        }
    }

In the real life the user will send us a number (1, 2, 3 or 4) representing each enum value in the order they are declared.

so, is it possible to cast like this?

det.documentStatus = (detallistaDocumentStatus)3;

if not, how could I get the enum value using an integer as an index, we are using a lot of enums, so we want to do something generic and reusable

  • 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-28T05:07:54+00:00Added an answer on May 28, 2026 at 5:07 am

    Yes, it’s possible to cast Enum to int and vice versa, because every Enum is actually represented by an int per default. You should manually specify member values.
    By default it starts from 0 to N.

    It’s also possible to cast Enum to string and vice versa.

    public enum MyEnum
    {
        Value1 = 1,
        Value2 = 2,
        Value3 = 3
    }
    
    private static void Main(string[] args)
    {
        int enumAsInt = (int)MyEnum.Value2; //enumAsInt == 2
    
        int myValueToCast = 3;
        string myValueAsString = "Value1";
        MyEnum myValueAsEnum = (MyEnum)myValueToCast;   // Will be Value3
    
        MyEnum myValueAsEnumFromString;
        if (Enum.TryParse<MyEnum>(myValueAsString, out myValueAsEnumFromString))
        {
            // Put logic here
            // myValueAsEnumFromString will be Value1
        }
    
        Console.ReadLine();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
Let's say that I got the following class and enum: public class MyModel {
I've got the following : enum Type { One = 0, Two}; class MySubClass
I have got following code: I have a enum: public enum HardwareInterfaceType { Gpib
Let's say that I've got the following class hierarchy : public static class Constants
I've got following class and template function: template <size_t num> class String{ public: char
I got the following model piece of code: public enum EnumTest { [Description (Enum
I've got the following enum: public enum myEnum { ONE(ONE), TWO(TWO); private String name;
I've got following problem: (c#) There is some class (IRC bot), which has method,
i've got following example xml: <entity id=1> <name>computer</name> <type>category</type> <entities> <entity id=2> <name>mac</name> <type>category</type>

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.