How do I ensure that my list contains all unique items in Linq?
I have a List<T> in my class. I want to make sure that it contains unique items.
Re: How do I ensure that my list contains all unique items in Linq?
For the query itself, use the ".Distinct()" clause.
Other than that, use a HashSet (.NET 3.5 or higher) or a Dictionary instead for unique values.
Re: How do I ensure that my list contains all unique items in Linq?
Quote:
Originally Posted by
David Anton
For the query itself, use the ".Distinct()" clause.
Other than that, use a HashSet (.NET 3.5 or higher) or a Dictionary instead for unique values.
I am not querying the list, though I suppose, I could do that too. I went with a HashSet object.