Re: what is the best datatype for..
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 19 Nov 2007 11:11:17 -0500
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
.
- References:
- what is the best datatype for..
- From: calvert4rent
- what is the best datatype for..
- Prev by Date: Re: Where i can define global variable?
- Next by Date: Re: what is the best datatype for..
- Previous by thread: what is the best datatype for..
- Next by thread: Re: what is the best datatype for..
- Index(es):
Relevant Pages
|