[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1304
  • Last Modified:

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 =-
0
deathtospam
Asked:
deathtospam
  • 2
1 Solution
 
adatheladCommented:
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now