String Comparisons

Using string.Equals() method

if (string.Equals(first, second))
{
    Console.WriteLine("Equal");
}
else
{
    Console.WriteLine("Not equal");
}

Alternatively, using '==' operator

string first = "ABC";
string second = "ABc";

if (first == second)
{
    Console.WriteLine("Equal");
}
else
{
    Console.WriteLine("Not equal");
}

Last updated