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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:18:54+00:00 2026-05-24T09:18:54+00:00

Consider the following enum: [Flags] public enum MyEnum { Option1 = 0, Option2 =

  • 0

Consider the following enum:

[Flags]
public enum MyEnum
{
    Option1 = 0,
    Option2 = 1,
    Option3 = 2,
    Option4 = 4
}

Is there a way in which I can get the string equivalent (not the value) as a CSV string? Normally I can use the Enum.GetName function to convert a type to the string representation, however, if you use a combination this returns null.

So basically I would like to convert:

var options = MyEnum.Option1 | MyEnum.Option3;

into

"Option1, Option3" 

Then I would like to be able to convert “Option1, Option3” back to MyEnum.Option1 | MyEnum.Option2.

Suggestions?

  • 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-24T09:18:55+00:00Added an answer on May 24, 2026 at 9:18 am

    Well, aside from Option1 not making much sense in a flags enum, this just works by default using Enum.Parse and Enum.ToString().

    Start with this:

    var options = MyEnum.Option2 | MyEnum.Option3;
    Console.WriteLine(options.ToString());
    // Outputs: Option2, Option3
    

    Then you can always do this:

    var options2 = (MyEnum) Enum.Parse(typeof (MyEnum), "Option2, Option3");
    

    Now try this:

    Console.WriteLine((options2 & MyEnum.Option2) == MyEnum.Option2);
    Console.WriteLine((options2 & MyEnum.Option4) == MyEnum.Option4);
    // Outputs:
    //    true
    //    false
    

    Which seems like it does exactly what you wanted (again, ignoring the fact that Option1 in your example will never occur)

    docs: Enum.Parse

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

Sidebar

Related Questions

Let's consider the following enum in C# public enum ScrollMode : byte { None
Consider the following class: class Foo { enum Flags {Bar, Baz, Bax}; template<Flags, class
Consider the following code: public enum SomeCode { NIF = 0 ,NIE = 1
How can I use C++ enum types like C#? consider following definition in c++
Consider the following method, public void Add(Enum key, object value); Since Enum is a
I have the following enum: [Flags] public enum PostAssociations { None = 0x0, User
I'm creating a flags enumeration in C#, similar to the following: [Flags] public enum
Consider the following function: public enum Operator { EQUAL = 1, GREATER_THAN = 2
Consider the following very basic WCF service implementation: public enum TransactionStatus { Success =
Background Consider the following: template <unsigned N> struct Fibonacci { enum { value =

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.