Reputation: 1328
I have a array of object which is generated dynamically. I want to store this object 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.
How to store and push the array of object dynamically in to the new array variable.
Upvotes: 0
Views: 3504
Reputation: 29036
Are you looking for an 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};
You can access these items to the console by using the following loops:
foreach(var array in objColl)
foreach(var item in (object[])array)
Console.WriteLine(item.ToString());
You can take a look at this example
Upvotes: 2
Reputation: 957
List<object[]> list = new List<object[]>();
list.Add(yValues);
list.Add(yValues1);
list.Add(yValues2);
You have then one list containing objects for all arrays;
Upvotes: 2
Reputation: 46005
want to store this object in a array collection.
objColl
musst be a jagged array object[][]
to contain a array of arrays
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 };
Upvotes: 4