C#: double 的 Array.Sort 方法?

标签 c# arrays sorting

我有一个数组 ( double ): ox_test 具有已知数量的元素。

当我编码时:

Array.Sort(ox_test);

然后,看看数组是否已排序:

for (int y = 1; y <= ox_test.Length; y++)
     MessageBox.Show(".x: " + ox_test[y]);

.. 我得到 ... 0, 0, 0, 0, 0(如果元素数为 5)。请帮忙,谢谢!

所以我修改了两个for循环:

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

最佳答案

// 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

关于C#: double 的 Array.Sort 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10266751/

相关文章:

c# - 从单独的线程发送邮件时出错 - asp.net/C#

c# - 从现有表达式创建新表达式

php - 使用 PHP 将单列从 CSV 转换为简单数组

c - 在c中使用sift down方法实现堆排序

javascript - 对不同集合上匹配 id 的对象数组进行排序

c# - 具有Simple.OData.Client的DTO

c# - 数据网格 - "Two-way binding requires Path or XPath."

arrays - node.js:返回模块中的数组

javascript - 如何在 Javascript 中拆分数组内的数组?

list - 榆树排序和[可比]