Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Ability to make switch() statement case-insensitive?

Posted on 2006-11-22
2
1,268 Views
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 =-
0
Comment
Question by:deathtospam
  • 2
2 Comments
 
LVL 23

Accepted Solution

by:
adathelad earned 500 total points
ID: 17997231
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
 
LVL 23

Expert Comment

by:adathelad
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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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