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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:41:31+00:00 2026-06-12T08:41:31+00:00

Possible Duplicate: convert an enum to another type of enum When casting between enums

  • 0

Possible Duplicate:
convert an enum to another type of enum

When casting between enums of different types, is it possibly to directly cast from one type to the other like so?

LicenseTypes type;
TypeOfLicense type2;

type2 = (TypeOfLicense)type;

Or is it necessary to cast the enum to an int first? The compiler doesn’t complain, but I want to make sure I’m not going to get some kind of funky casting exception at runtime.

This may seem like an odd thing to do, but both enums are identical in structure and value. Only the type names differ in this case.

  • 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-12T08:41:31+00:00Added an answer on June 12, 2026 at 8:41 am

    Although its a duplicate and I have flagged it as well. You can do simple casting, beucase the underlying type is int, you can do:

    LicenseTypes type = (LicenseTypes)TypeOfLicense.value3;
    

    Here type will hold value ‘0’;

    Suppose you have:

    public enum LicenseTypes 
    {
        value1,
        value2,
    }
    public enum TypeOfLicense
    {
        value3, 
        value4,
        value5
    }
    

    But if you try to Cast TypeOfLicence.value5 then the variable type will hold the int value 2

    LicenseTypes type = (LicenseTypes)TypeOfLicense.value5;
    

    You can also look at this link for creating extension methods for conversion between enums. (Its the accepted answer of the similar question)

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

Sidebar

Related Questions

Possible Duplicate: Convert one date format into another in PHP Starting from: $date =
Possible Duplicate: How do I Convert a string to an enum in C#? Enums
Possible Duplicate: Convert some code from C++ to C I've got some code that
Possible Duplicate: How do I Convert a string to an enum in C#? I
Possible Duplicate: Convert from char* to NSString? I have char myChar = 'r' How
Possible Duplicate: Convert one date format into another in PHP I know there are
Possible Duplicate: How to convert enum value to int? I'm trying to assign values
Possible Duplicate: Cast string to enum with enum attribute I have a enum like
Possible Duplicate: Convert a number range to another range, maintaining ratio So I have
Possible Duplicate: convert month from name to number I have a simple (yet interesting)

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.