Users Pricing

forum

home / developersection / forums / write a program to test a switch case using an enum as a string, not an integer in c#.

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

Ashutosh Patel 725 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.


Ashutosh Patel

Jr. Software Developer

I am a software developer at MindStick soft. Pvt. ltd. I joined this company in august 2021 after completing my post-graduation course. I love to see the historical places of my country.


1 Answers

Markdown for AI

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

Open .md