I have a List that has duplicates of objects. To solve that, I need to convert the List into a HashSet (in C#). Does anyone know how?
Make sure your object's class overrides Equals
and GetHashCode
and then you can pass the List<T>
to HashSet<T>
constructor.
var hashSet = new HashSet<YourType>(yourList);
You may see: What is the best algorithm for an overridden System.Object.GetHashCode?