Compare two objects by value in C#


In C# compare method is not straight forward. To compare two objects 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);
}

view raw

Helper.cs

hosted with ❤ by GitHub

This method compare the types of two object and then check their value.

Leave a comment