Hi

I want to create text box array at desing time.It means i want to create text box like Text box1[1],TextBox[2],TextBox[3].How do u create it in desing time in C#.

Thanks
Tank50

Hi

I want to create text box array at desing time.It means i want to create text box like Text box1[1],TextBox[2],TextBox[3]. How do u create it in desing time in C#.
Thanks
Tank50

You may create an array of TextBox at runtime (dynamically).

.....
  ....
  TextBox []t=new TextBox[5];  // Array of Five TextBox object variables.
   // Create an instance of each TextBox
   for(int i=0;i<t.Length;i++) {
       t[i]=new TextBox();
       ..... 
   }
  .....
  .....

May I ask why there is a need to add

t[i] = new TextBox();

when there is already a declaration

TextBox []t=new TextBox[5];

?

Thanks.

TextBox[] t = new TextBox[5]

The declaration above is to make the array itself, and;

t[i] = new TextBox();

This one is for creating instances of each members in the array. Actually, the explanations are included in the Syntax made by the poster above you. Just gotta pay a little more attention. :P

Yes you are right.
Sorry about it. Thans for the explanation :)

TextBox[] t = new TextBox[5]

The declaration above is to make the array itself, and;

t[i] = new TextBox();

This one is for creating instances of each members in the array. Actually, the explanations are included in the Syntax made by the poster above you. Just gotta pay a little more attention. :P

This article has been dead for over six months. Start a new discussion instead.