双数组到对象数组? [英] Double Array to Object Array?
问题描述
我有以下数组:
double[] Series = new double[] { 7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6 }
系列调试视图:
> Series
--> [0]
--> [1]
--> ...
--> [10]
--> [11]
当我写以下内容时:
object[] object_array = new object[] { Series }
object_array调试视图:(不止一个级别)
object_array debugging view : (more than one level)
> object_array
--> [0]
----> [0]
----> [1]
----> ...
----> [10]
----> [11]
我写以下内容来防止出现新水平:
I write following to prevent new level:
object[] object_array = new object[Series.Length];
for (int i = 0; i < Series.Length; i++)
{
object_array[i] = Series[i];
}
这是其他解决方案之一。但我认为,也许有更好的方法可以做到这一点。使用上面的循环对我来说有问题吗?还是以其他方式?
This is the one of the other solutions. But I think, there may be a better way to do this. Is there a problem for me to use above loop? Or different way?
(我使用highcharts。如果给出的数组包含多个级别,则不起作用。)
(I use highcharts. If I give array that contains more than one level, it does not work.)
谢谢。
推荐答案
这样做
object[] object_array = new object[] { Series }
您正在分配一个double数组作为数组object_array的第一个对象项。您实际上是在创建一排二维数组。您可以使用类似这样的东西:
you are assigning a double array as the first object item of the array object_array. You are actually creating 2D array with one row. You can use something like this:
double[] Series = new double[] { 7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6 };
object[] object_array = new object[Series.Length];
Series.CopyTo(object_array, 0);
这篇关于双数组到对象数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!