ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

EqualsByValue

Determines whether two String objects have the same value. Null and String.Empty are considered equal values.

Source

public static bool EqualsByValue(this string inString, string compared)
{
    if (string.IsNullOrEmpty(inString) && string.IsNullOrEmpty(compared))
        return true;

    // If we get here, then "compared" necessarily contains data and therefore, strings are not equal.
    if (inString == null)
        return false;

    // Turn down to standard equality check.
    return inString.Equals(compared);
}

Example

bool areEqual = a.EqualsByValue(b);

Author: Omniscient Technology Inc

Submitted on: 5 okt. 2009

Language: C#

Type: System.String

Views: 4132