Reputation: 2169
I have an array ( double ) : ox_test with a known number of elements.
when I code :
Array.Sort(ox_test);
and then, just to see if the array it's sorted :
for (int y = 1; y <= ox_test.Length; y++)
MessageBox.Show(".x: " + ox_test[y]);
.. I get ... 0, 0, 0, 0, 0 ( if the number of elements was 5 ). Please help, thank you!
So i modified the both for loops:
for (int y = 0; y < ox_test.Length; y++)
MessageBox.Show(".x: " + ox_test[y]);
// HERE i get the values not sorted but != 0
Array.Sort(ox_test);
for (int y = 0; y < ox_test.Length; y++)
MessageBox.Show(".x s: " + ox_test[y]);
// HERE i get only 0 values
Upvotes: 1
Views: 14636
Reputation: 31
Try with this code:
Array.Sort(ox_test);
foreach (double i in ox_test)
{
Console.Write(i + " ");
}
Upvotes: 0
Reputation: 3229
// sort double array
double[] doubleArray = new double[5] { 8.1, 10.2, 2.5, 6.7, 3.3 };
Array.Sort(doubleArray);
// write array
foreach (double d in doubleArray) Console.Write(d + " "); // output: 2.5 3.3 6.7 8.1 10.2
Upvotes: 7
Reputation: 3821
You should start from 0 instead of 1.
for (int y = 0; y < ox_test.Length; y++)
MessageBox.Show(".x: " + ox_test[y]);
Also, please be sure of initialization of ox_test
array.
Upvotes: 1