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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:40:52+00:00 2026-06-05T10:40:52+00:00

I know that to parse a string to specific enum like: enum AnEnumType {

  • 0

I know that to parse a string to specific enum like:

enum AnEnumType 
{
   TEST_,
   OTHER_TEST_,
   OTHERS_
}

enum OtherEnumType 
{
   TEST1_,
   OTHER_TEST1_,
   OTHERS1_
}


string aValueString = "TEST_";

AnEnumType result = (AnEnumType)Enum.Parse(typeof(AnEnumType), aValueString);

So, I want to create a function, a generic one which use parser for my enum(s) like:

public Type ConvertStringToAnEnum(string value, Type anyType){

return (anyType)Enum.Parse(typeof(anyType), aValueString);
}

But I guess that is not OK…

How to make the function which parse any enumeration type specified as argument in function?

like I want to call OtherEnumType result = ConvertStringToAnEnum("TEST1_", OtherEnumType)

  • 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-05T10:40:53+00:00Added an answer on June 5, 2026 at 10:40 am

    Make the generic method generic:

    public T ConvertStringToAnEnum<T>(string value){
      return (T)Enum.Parse(typeof(T), value);
    }
    

    Usage:

    OtherEnumType result = ConvertStringToAnEnum<OtherEnumType>("TEST1_");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a date time string that I don't know how to parse it
I would like to know if ParseExact is faster than Parse. I think that
I have string with product information and I would like to parse that string
Does anybody know a Java MIDI parser that will parse a MIDI into a
I'm using Java 6. I want to parse XHTML that I know is well-formed.
I know that some of the Microsoft employees are members of StackOverflow like the
I have a static method like this public static string DoSomethingToString(string UntrustedString) { //parse
I know that using Regular expressions to parse or manipulate HTML/XML is a bad
If I'm parsing something like the Apache website, I have one specific problem that
I'd like to extract a date from any string entered. But not specific to

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.