There are "N" number of Textboxes on a Form,
I want to get the values in the textboxes in an Array.
using "For" loop,
Can any help me out with this.
You can get all the controls on a form by calling this.Controls and loop through those comparing the control to a TextBox, when it is a TextBox you add the value to the array you are mentioning.
I'd use something like this:
List<string> values = new List<string>();
foreach(Control c in this.Controls)
{
if(c is TextBox)
{
/*I didnt need to cast in my intellisense, but just in case!*/
TextBox tb = (TextBox)c;
values.Add(tb.Text);
}
}
string[] array = values.ToArray();
Control doesn't have a Text property, I think you need to use as instead of is and check for != null.