Users Pricing

forum

Home Forums Write a program to test a switch case using an enum as a string, not an integer in C#. – MindStick

Write a program to test a switch case using an enum as a string, not an integer in C#.

Ashutosh Patel 793 29 Mar 2023

This is Enum 

 public enum PostType
 {
      Article,
      Blog,
};

I am trying to write code but through  Exception. The code is here.

string  _type = "article";
switch (_type.ToLower())
            {
                case PostType.Article.ToString().ToLower():
                {
                    query = String.Format(@"Up date article");
                    break;
                }
                case PostType.Blog.ToString().ToLower():
                {
                    query = String.Format("UP  date blog");
                    break;
                }
                default: break;
            }

Please help me.


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md