Results 1 to 4 of 4

Thread: [RESOLVED] Count of unique values in a collection

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Resolved [RESOLVED] Count of unique values in a collection

    I have a sorted collection of 4-digit numbers and many of the numbers are duplicated. I'm looking for a quick way to get a count of each unique value. For example if 1234 occurs 3 times in the collection and 2468 occurs 5 times in the collection I'd like to wind up with an array that contains 1234|3 and 2468|5.

    Could I use a Dictionary by itself without having to use (and sort) a collection and a separate array?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Count of unique values in a collection

    Should be able to... check the dictionary to see if the key exists, if it does, +1 the value, if not, add it and set the count to 1.
    There may even be a way to use linq to aggregate the data for you and return an array.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Count of unique values in a collection

    Should be able to... check the dictionary to see if the key exists, if it does, +1 the value, if not, add it and set the count to 1.
    Can you supply sample code? I haven't had any experience with dictionaries.

  4. #4

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