从列表中填充一个双精度数组 [英] populating a double array from a list

查看:63
本文介绍了从列表中填充一个双精度数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何从列表中填充数组的元素


代替这个

Hi How would I populate the elements of an array from a list


instead of this

double[][] items ={
         new double[3] {.05,.05,0},
         new double[3] {0,0,1},
         new double[3]{.1,.05,1}};


元素在arraylist中
新的double [3] {i,i ++,i ++}?


Elements are in a arraylist
new double[3]{i,i++,i++}?

推荐答案

类似的东西应该对您有用.

Something like this should work for you.

ArrayList alist = new ArrayList();
alist.Add(new double[] { 3.0, 5.1, 4.8});
alist.Add(new double[] { 7.9, 9.1, 1.3 });
alist.Add(new double[] { 8.6, 6.2, 5.7 });

double[][] jagged = new double[alist.Count][];

for (int i = 0; i < alist.Count; i++)
{
    double[] a = (double[])alist[i];

    jagged[i] = a;
}

//test - show the array
for (int i = 0; i < jagged.Length; i++)
{
    for (int n = 0; n < jagged[i].Length; n++)
    {
        MessageBox.Show(jagged[i][n].ToString());
    }
}


这篇关于从列表中填充一个双精度数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆