I am trying to work with a 2-D array of ints but I have some problems. What i want to do is something like this:
int[,] values = new int[Apples,1]; //Apples = say, 50
What I want to end up with is something like this:
values={ {393,0},{120,1},{9133,2},{75,3},...}; but the 393, 120, etc. are values generated in a for loop. That is to say, I cannot initialize the array by assigning it like { {xx},{yy}}, etc. So
I want to do something like
for (int i = 0; i<Oranges; i++) {
values[i,0]={functionCall(),i};
}
where functionCall is prototyped like int functionCall(){...}
but that assignment values[i,0] doesn't work. After this assignment process has completed, I need to sort the array by the first column, so I would get a new array valuesSorted, like this:
valuesSorted={ {75,3},{120,1},{393,0},{9133,2},...}
so when I iterated over valuesSorted I would get data in that order.
Any ideas how I would do this?
new int[Apples, 2]instead? And do you have to use a multi-dimensional array here instead of a single-dimensional array of some appropriate type? (Are you really representing pairs of numbers?)Tuple<int, int>[]Pair<T>struct and making an array of pairs of integers.