Pages

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

Wednesday, December 18, 2013

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

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.


No comments:

Post a Comment