Ability to make switch() statement case-insensitive?

C#'s switch() statement is case-sensitive.  Is there a way to toggle it so it becomes case-insensitive?


-= DeathToSpam =-
LVL 9
Mass Dot NetAsked:
Who is Participating?
 
adatheladConnect With a Mentor Commented:
Hi,

Convert the string to "switch" on to lowercase (or uppercase if you prefer):
e.g.
switch (yourString.ToLower())
{
    case "somelowercasestring":
        // Do something
        break;

    case "anotherlowercasestring":
        // Do something else
        break;
}
0
 
adatheladCommented:
Also just to add, it's not that C#'s switch statement is case-sensitive - more that C# as a whole is case-sensitive
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.