0

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.

1

3 Answers 3

4

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 };
Sign up to request clarification or add additional context in comments.

Comments

2
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;

Comments

2

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

3 Comments

Stay type-safe. Why not use List<T>?
@HimBromBeere: yep that would be a better option if all are of same type.
Well, they are of the same type, namely object[].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.