Results 1 to 3 of 3

Thread: How do I ensure that my list contains all unique items in Linq?

  1. #1

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,226

    Question 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

  2. #2
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    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.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  3. #3

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,226

    Re: How do I ensure that my list contains all unique items in Linq?

    Quote Originally Posted by David Anton View Post
    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
  •  



Click Here to Expand Forum to Full Width