-
Sep 6th, 2012, 03:12 PM
#1
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.
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Sep 6th, 2012, 07:20 PM
#2
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.
Last edited by David Anton; Sep 6th, 2012 at 07:24 PM.
-
Sep 7th, 2012, 06:54 AM
#3
Re: How do I ensure that my list contains all unique items in Linq?
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.
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|