Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将对象数组存储在另一个变量c中#_C#_Asp.net_Arrays - Fatal编程技术网

C# 将对象数组存储在另一个变量c中#

C# 将对象数组存储在另一个变量c中#,c#,asp.net,arrays,C#,Asp.net,Arrays,我有一个动态生成的对象数组。我想将此对象存储在数组集合中 object[] yValues = new object[] { 2000, 1000, 1000 }; object[] yValues1 = new object[] { 2000, 1000, 1000 }; object[] yValues2 = new object[] { 2000, 1000, 1000 }; objColl = {yValues, yValues1, yValues2};// I want to sto

我有一个动态生成的对象数组。我想将此对象存储在数组集合中

object[] yValues = new object[] { 2000, 1000, 1000 };
object[] yValues1 = new object[] { 2000, 1000, 1000 };
object[] yValues2 = new object[] { 2000, 1000, 1000 };

objColl = {yValues, yValues1, yValues2};// I want to store something like this in a array collection.
如何存储对象数组并将其动态推入新的数组变量

要将此对象存储在数组集合中

object[] yValues = new object[] { 2000, 1000, 1000 };
object[] yValues1 = new object[] { 2000, 1000, 1000 };
object[] yValues2 = new object[] { 2000, 1000, 1000 };

objColl = {yValues, yValues1, yValues2};// I want to store something like this in a array collection.
objColl
must不能是锯齿状数组
object[][]
以包含数组数组

object[] yValues = new object[] { 2000, 1000, 1000 };
object[] yValues1 = new object[] { 2000, 1000, 1000 };
object[] yValues2 = new object[] { 2000, 1000, 1000 };

object[][] objColl = { yValues, yValues1, yValues2 };
List List=新列表();
列表。添加(Y值);
列表。添加(Y值1);
列表。添加(Y值2);

然后有一个列表,其中包含所有数组的对象

你在找arrayList吗

object[] yValues = new object[] { 2000, 1000, 1000 };
object[] yValues1 = new object[] { 2000, 1000, 1000 };
object[] yValues2 = new object[] { 2000, 1000, 1000 };

ArrayList objColl = new ArrayList(){yValues, yValues1, yValues2};
您可以使用以下循环访问控制台中的这些项目:

foreach(var array in objColl)
        foreach(var item in (object[])array)
           Console.WriteLine(item.ToString());

您可以看看

您的解决方案是JaggedArray。保持安全。为什么不使用
List
?@HimBromBeere:是的,如果所有对象都是相同的类型,那么这将是一个更好的选择。嗯,它们是相同的类型,即
object[]