The best way to compare two objects by value in C#

To compare to object by value we can use the following code snippet.

1
2
3
4
private static bool CompareValue(object o1, object o2)
{
    return o1.GetType() == o2.GetType() && Object.Equals(o1, o2);
}

This method compare the types of two object and then check their value.
Previous
Next Post »