[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?
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
Re: Count of unique values in a collection
Quote:
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.
Re: Count of unique values in a collection
Found an easy solution using a worksheet, =Unique and =CountA. No collection or Dictionary needed.