C#创建数组的数组 [英] C# Creating an array of arrays
本文介绍了C#创建数组的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创建一个将要使用的重复数据数组的数组,类似如下:
I'm trying to create an array of arrays that will be using repeated data, something like below:
int[] list1 = new int[4] { 1, 2, 3, 4};
int[] list2 = new int[4] { 5, 6, 7, 8};
int[] list3 = new int[4] { 1, 3, 2, 1 };
int[] list4 = new int[4] { 5, 4, 3, 2 };
int[,] lists = new int[4, 4] { list1 , list2 , list3 , list4 };
我无法得到它,它的工作,我想知道如果我接近这个错误。
I can't get it it work, and I'm wondering if I'm approaching this wrong.
我正在试图做的是创造某种方法来创建一个长长的清单,如果这些值,所以我可以在一个特定的顺序处理它们,反复进行。喜欢的东西,
What I'm attempting to do is create some sort of method to create a long list if the values so I can process them in a specific order, repeatedly. Something like,
int[,] lists = new int[90,4] { list1, list1, list3, list1, list2,(and so on)};
for (int i = 0,i < 90;++i) {
doStuff(lists[i]);
}
和具有为了传递给doStuff()的阵列。我要对这个完全错误的,还是我失去了一些东西,用于创建数组的数组?
and have the arrays passed to doStuff() in order. Am I going about this entirely wrong, or am I missing something for creating the array of arrays?
推荐答案
您需要做的是这样的:
int[] list1 = new int[4] { 1, 2, 3, 4};
int[] list2 = new int[4] { 5, 6, 7, 8};
int[] list3 = new int[4] { 1, 3, 2, 1 };
int[] list4 = new int[4] { 5, 4, 3, 2 };
int[][] lists = new int[][] { list1 , list2 , list3 , list4 };
另一种方法是创建一个列表与LT; INT []&GT;
类型:
List<int[]> data=new List<int[]>(){list1,list2,list3,list4};
这篇关于C#创建数组的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文