将一维数组分配给多维数组 [英] assigning single dimensional array to multidimensional array

查看:132
本文介绍了将一维数组分配给多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

static void Main()
        {
               double [] tabseq= new double[3];
               inputvalue(tabseq);
        }
        public static void inputvalue(double[] tabseq)
        {
            int i;
            string invalue;
            Console.Write("enter tab seq");
            for (i = 0; i < 3; i++)
            {
                invalue = Console.ReadLine();
                tabseq[i] = double.Parse(invalue);
            }
        }


实际上,我的问题是,我无法传递单个输入.....我必须接受输入并将其存储在某个地方,将其传递给k表示算法是堆...我该怎么办呢?


actualy my problem is,i cant pass single input..... i have to take input and store it somewhere, pass it to k means algorithm as heap... how could i do that

推荐答案

是的,可能的是:一维和多维数组都包含项.因此,您可以自由地将项目从前者复制到后者(反之亦然),例如
Yes it is possible: both single dimension and multiple dimensions arrays contain items. So you are free to copy items from the former to the latter (and viceversa), e.g.
double[] a = new double[4];
a[0] = 7.0;
a[1] = 1.0;
a[2] = .05;
a[3] = .05;
double [,] b = new double[2,2];
for (int i=0; i<2; i++)
  for(int j=0; j<2; j++)
    b[i,j]=a[i*2+j];


也可以考虑使用通用列表,例如,具有浮点数列表:
Also you can consider using generic lists , for example to have a list of float numbers :
List<float> floats = new List<float>();



或具有浮点数的二维列表,请尝试:



Or to have two dimensional list of floats try :

List<List<float>> AllData = new List<List<float>>();



它将为您提供更多的编程能力.

希望对您有所帮助.



It will give you more programming power.

Hope it helps.


这篇关于将一维数组分配给多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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