Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating variable sized arrays

I have been creating arrays for different controls as follows, e.g:

private TextBox[] Array_TextBoxes;
private CheckBox[] Array_CheckBoxes;
private RadioButtonList[] Array_radioButton;

Array_TextBoxes= new TextBox[4];
Array_CheckBoxes= new CheckBox[5];
Array_radioButton= new RadioButtonList[10];

Is there any ways of creating them so that I do not need to specify the size/length? I.e. is it possible to make these control arrays variable sized?

Thanks!

like image 983
viv_acious Avatar asked Sep 22 '26 19:09

viv_acious


1 Answers

Arrays must be assigned a length, if you want to allow for any number of elements use the List class, like this

List<TextBox> textBoxList=new List<TextBox>();

and add controls into this collection

 textBoxList.Add(new TextBox());
like image 152
Sachin Avatar answered Sep 25 '26 09:09

Sachin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!