I have been having a nagging problem for a few days, here's what I'm trying to do:
I am writing a program that manipulates various set of numbers in multiple ways and so far so good- now I control one of such computations using a loop, so that each time it goes round it outputs an int value x and an int value y.
Now x is sequential, being derived from a counter, y is just a variable number.
So I repeat I have a simple loop reading the datarows
foreach (DataRow dr in dTable.Rows)
{
....
I output x and y (after some calculations)
....
}
Now I would like to get this two values for each row and at the end do a sort based on value y! Originally I was simply going to use a hashmap like I used to do in java and do a sort by value, but I am finding it hard to do in c# as the datadictionary (I don't want to use a temp table either) only allows you sorting by key (in my case x)
Now what approach should I take? - Use the output pair values of my loop as the input for a datatable? - Use a 2d array which looks pretty complex but eventually is the only way to maintain the pair relation between x and y?
Or is there any other way to do do the equivalent of a java hashmap sorting by value?
If the y values are unique, then maybe:
This is then both keyed and sorted by the y values, but the keys must be unique.
To make things more complicated,
SortedDictionary<,>
is also keyed and sorted; some minor differences in the O though - whether add or fetch is cheapest etc.