Quote:
Originally Posted by Jimbo
There's a couple problems with this code. First, you need to add the controls to the collection, not the Text properties. Also, you can't add them by giving a string with the control's name (unfortunately  ). Also, you should use the length of the ArrayList instead of hardcoding a length, to make sure you get each one. Lastly, an optional recommendation, you could use a generic collection so that you don't have to use the Object type for each element. For exmaple:
List<TextBox> theBoxes = new List<TextBox>(); // when you create a new textbox, add it TextBox foo = new TextBox(); theBoxes.Add(foo); // later on, just go over each element in the arraylist and set each of their text properties foreach (TextBox t in theBoxes) { t.Text = String.Empty; } // alternatively: //for(int i = 0; i < theBoxes.Count; i++) // theBoxes[i].Text = String.Empty;
Instead of just using [code] you can often put [code=language] to get colored syntax. There are some anomalies as I recall, such as C++ being [code=cpp]. For C#, it's just [code=c#] though. 
|
From what I can see, the main difference between the ArrayList and List is that with the List you need to specify a class, and with the ArrayList you don't specify a type, am I right?
Also, maybe I didn't explain myself well, but I was looking for an alternative to having a line of code for each textbox, eg:
theBoxes.Add(answer1);
theBoxes.Add(answer2);
theBoxes.Add(answer3);
and so on...
Thanks alot for the help!