Ability to make switch() statement case-insensitive?

Posted on 2006-11-22
Medium Priority
Last Modified: 2011-10-03
C#'s switch() statement is case-sensitive.  Is there a way to toggle it so it becomes case-insensitive?

-= DeathToSpam =-
Question by:Mass Dot Net
  • 2
LVL 23

Accepted Solution

adathelad earned 2000 total points
ID: 17997231

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

    case "anotherlowercasestring":
        // Do something else
LVL 23

Expert Comment

ID: 17997243
Also just to add, it's not that C#'s switch statement is case-sensitive - more that C# as a whole is case-sensitive

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Watch the video to know the simple way to remove or recover or reset lost or forgotten passwords of Outlook PST file. With Kernel Outlook Password Recovery tool such operation is very easy to perform. It is a freeware with limitation to use with 500…

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question