| ||||
Adding items to generic list
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
| ||||
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
AlanRank #669 · 3.6K reputationPosted Nov 28, 2007, 4:40 AM EST
You haven't said what the type parameter is for your generic List object (let's call it 'list'), but try this:
System.Text.StringBuilder temp = new System.Text.StringBuilder();
temp = temp.Append ("The items in your list are:");
temp = temp.Append (Environment.NewLine);
temp = temp.Append (Environment.NewLine);
for(int i = 0; i < list.Count; i++)
{
temp = temp.Append((i+1).ToString());
temp = temp.Append(" : ");
temp = temp.Append(list[i].ToString());
if (i < list.Count - 1)
temp = temp.Append(Environment.NewLine);
}
string listStr = temp.ToString();
temp = null;
MessageBox.Show(listStr);
You could also, of course, display the list items in a control, such as a multiline textbox, with a line such as the following:
textBox1.Text = listStr;
ramya naidu12 reputationPosted Nov 29, 2007, 11:14 PM EST