Re: what is the best datatype for..

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I would store this in a Dictionary<int, int> where the key is the id and
the value is the count.

Then, when you need to sort the keys, I would enumerate through the
KeyValuePair instances and sort those (Dictionary<TKey, TValue> implements
IEnumerable<KeyValuePair<TKey, TValue>>). You can simply put them into an
array and then call the static Sort method on the Array class, passing in an
anonymous method for the Comparison<T> delegate (which in this case, would
be Comparison<KeyValuePair<int, int>>) which would compare the values based
on the count.

You could also get away with using a DataTable with an id column and a
count column, and then just placing a data view on the data table which is
sorted by the count.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

<calvert4rent@xxxxxxxxx> wrote in message
news:89f5d237-ed03-46ce-862d-1f34afa54333@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I need to some sort of data type that will hold a listing of ID's and
their counts/frequency. As I do some processing I get an ID back
which I need to store and keep an accurate count for how many times
that ID is listed. For example I might get a listing of these
numbers:
1,4,6,23,6,2,54,1,6,23,2,4,1,6

I will get those numbers one at a time and need to build something
like
1,3
4,2
6,4
23,2
2,2
43,1

In above number X,Y:
X- is the number
Y- is the count of the number

I then need to sort the data on the Y (the count) column:
6,4
1,3
4,2
23,2
2,2
43,1

Can anyone suggest how best to do this. Any suggestions or help is
much appreciated!

Thanks,

Calvert


.



Relevant Pages

  • [8FOLD] Template #3
    ... "You lead a very eventful life, don't you, Mr. Kidman?" ... lunatics collapsing in the middle of your store... ... threats have some sort of motivation behind them. ...
    (rec.arts.comics.creative)
  • Re: Bad feelings in Wickes
    ... to sort it out. ... insisted that I should approach the exit without the carrier bag, ... test if the machine would beep. ... A few years My brother and I went into a Wicks Store and bought a large ...
    (uk.legal)
  • C 128s ROM socket
    ... sort of a new topic, so I didn't reply to that. ... I've thought about that ROM socket in the C128 a lot and have on occasion ... So I'm hoping to use something on the IEC port to store more ... up trying to read/write to a serial flash ram chip via the user port.. ...
    (comp.sys.cbm)
  • Re: all this talk of clothing made in china...
    ... USA." and in her store, she's only going to sell items that are made ... and just the sort of person that should think about joining the ... I was brought up by parents (mother, mostly) who instilled me with all ...
    (uk.people.support.depression)
  • Re: OT: Materialism and reproductive success.
    ... My fear is that this sort of behavior is growing rather than ... matches in the store at Christmastime over who could take the last one. ... Robert Grumbine http://www.radix.net/~bobg/ Science faqs and amateur activities notes and links. ... Sagredo (Galileo Galilei) "You present these recondite matters with too much ...
    (talk.origins)