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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:43:10+00:00 2026-06-11T02:43:10+00:00

There’s lots of questions on here about converting strings to an enum value. Generally,

  • 0

There’s lots of questions on here about converting strings to an enum value. Generally, the answer looks something like the answers on this question:

StatusEnum MyStatus = (StatusEnum) Enum.Parse( typeof(StatusEnum), "Active", true );

While that’s a perfectly reasonable answer, and you can write a method to simplify the call, it doesn’t answer the question of why Enum.Parse() returns an object instead of the appropriate enum value. Why do I have to cast it to StatusEnum?


Edit:

Basically, the question is why is a function like this not part of the Enum class?

    public static T Parse<T>(string value) where T: struct 
    {
        return (T)Enum.Parse(typeof (T), value);
    }

This function works perfectly fine, does exactly what you’d expect. StatusEnum e = Enum.Parse<StatusEnum>("Active");.

  • 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-11T02:43:11+00:00Added an answer on June 11, 2026 at 2:43 am

    It does this because

    1. It predated generics and (even if it hadn’t:)
    2. Generic constraints can’t be enums (in the mainstream .NET languages)

    As such, Object is the only type that will always work for any type of enum.

    By returning object, the API is at least functional, even if a cast is required.

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

Sidebar

Related Questions

There are plenty of questions and answers to this like this question but I
There's a webpage with something annoying on it which I'd like to hide every
There is a properly formatted text in Html textarea which looks like : As
There's obviously something I'm missing here - I've been through the developer.android reference and
There are many similar questions to this one, but they all ask about setting
There are nice SO question and answers about this issue, but these options didn't
There was a similar question posted asking in general about alternatives to Qt. Well,
There are are 150 000 records in my comments table and about 1000 new
I would like to run a str_replace or preg_replace which looks for certain words
there are some actions I would like to globally specify on Ajax.BeginForm. (For example,

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.