CSharp - String String Comparing

String equality comparison

The following methods allow culture-aware or case-insensitive comparisons:

public static bool Equals(string a, string b,StringComparison comparisonType);
       public bool Equals(string value, StringComparison comparisonType);

StringComparison is an enum defined as follows:

public enum StringComparison{
       CurrentCulture,               // Case-sensitive
       CurrentCultureIgnoreCase,
       InvariantCulture,             // Case-sensitive
       InvariantCultureIgnoreCase,
       Ordinal,                      // Case-sensitive
       OrdinalIgnoreCase
}

For example:

Demo

using System;
class MainClass// w w  w .  j a  va  2  s  .  com
{
   public static void Main(string[] args)
   {
     Console.WriteLine (string.Equals ("foo", "FOO",
                        StringComparison.OrdinalIgnoreCase));   // True

   }
}

Result