— New online course!  Getting Started with Azure DevOps — Special launch price 50% off —

Case-insensitive string compare in .NET

by

I’ve been writing code full-time in C# for about 4 years now but every once in a while someone shows me something totally new.  Last week, one of the devs on my team showed me an override of String.Equals() that does a case-insensitive compare.  It kinda blew my mind that I’d never seen that before.


The following line of code evaluates to true.



string.Equals(“string number 1”, “String NUMBER 1”, StringComparison.CurrentCultureIgnoreCase) 


There is also a similar override of String.Compare().


Pretty handy, huh? 


-Ben


2 Responses to "Case-insensitive string compare in .NET"

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: