Saturday, 6 August 2016

C# - String Comparison ignore case the best way

As a C# developer, we tend to compare strings more frequently and we always tend to make lot of UpperCase and LowerCase conversions before comparing strings. 

To simply comparision try using "StringComparision.OrdinalIgnore", below is the sample

String string1 = "Test", string2 = "test";
Console.WriteLine("Strings are similar : {0}",string1.Equals(string2, StringComparison.OrdinalIgnoreCase).ToString());

Strings are similar : True

Refer below for more options:


No comments:

Post a Comment

Contact Form


Email *

Message *