Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing objects of value type N

What is the best way to compare objects of value type N? So I want to do a String, Integer, DateTime, etc comparison depending on the type of the object.

like image 887
MC. Avatar asked Feb 28 '23 05:02

MC.


1 Answers

IEqualityComparer<T>

Where T is the type you want to compare.

IEqualityComparer(T) Interface (System.Collections.Generic)

...you could also fall back on Object.Equals() and ValueType.Equals()

like image 122
Justin Niessner Avatar answered Mar 01 '23 18:03

Justin Niessner