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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:59:56+00:00 2026-06-08T20:59:56+00:00

If I declare an enum inheriting from ushort like this: public enum MyEnum :

  • 0

If I declare an enum inheriting from ushort like this:

public enum MyEnum : ushort { A = 0, B = 1 };

and then check its type like this:

if(typeof(MyEnum) != typeof(ushort))
            System.Diagnostics.Debugger.Break();

The breakpoint is called. Why is this happening?

  • 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-08T20:59:57+00:00Added an answer on June 8, 2026 at 8:59 pm

    It’s called because they’re not the same type! One is an enum type with an underlying value of type ushort, and the other is ushort itself. (Note that it’s not really “inheriting from ushort” even though it uses the same syntax – it’s really just saying “the underlying type is ushort“.)

    Why would you expect them to be the same type? If they were actually the same type, you’d lose a lot of the type safety of enums.

    It would be very odd to print typeof(MyEnum).Name and get UInt16 IMO.

    If you’re trying to determine the underlying type, you should use Type.GetEnumUnderlyingType:

    if (typeof(MyEnum).GetEnumUnderlyingType() == typeof(ushort))
    {
        // Yup, the underlying type is ushort
    }
    

    EDIT: Just for completeness, if MyEnum really did inherit from ushort, you’d still be testing for type equality. As cdhowie says in the comments, if you wrote:

    if (typeof(string) != typeof(object))
    {
        Debugger.Break();
    }
    

    that would still break into the debugger. You might want to look at Type.IsAssignableFrom for situations where you really want to make that kind of comparison.

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

Sidebar

Related Questions

I want to declare a new enum with non-default underlying type. This works: public
When I declare a enum variable like this: enum paint_colors { RED, GREEN, BLUE,
I'm trying to declare an enum type based on data that I'm retrieving from
I was hoping to declare in Enum type in a subclass and then access
I want to declare static(or not static) variable inside Enum. I need this because
Hi I have an enum declared like this: typedef enum { Top, Bottom, Center
I've got this enum at the top of my instance class: public Enum RecommendationPage
I have this basic setup: enum{ BASE, PRIMITIVE, ... }; class IUnknown{ public: bool
I often see Simple (non-Flags) Enums declared like this: enum Something { Thingy =
This is for the C preprocessor experts: How can I declare an enum with

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.