Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object array dynamic

Tags:

arrays

c#

I have the following line in my code:

object[] inputs = new object[] {"input1", "input2", "input3", "input4"};

I would like to know how (without knowing how many elements will be in the array) add dynamically using a loop like this:

object[] inputs;
foreach (string key in Request.Form.Keys)
{
     inputs[0] = key;
}

How could I do this?

Thanks in advance.

Best Regards.

like image 846
Sosi Avatar asked Dec 10 '22 14:12

Sosi


1 Answers

Could you just not use:

List<object> list = new List<object>();
list.Add(key);
like image 137
Datoon Avatar answered Dec 27 '22 23:12

Datoon