Hai iam working with list and i have added items to list and how can i find whether the items r added to list or not using windows applications using c# and how can i display the items in list in windows applications plz any one help me in this problem
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
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); }
ramya naiduPosted Nov 30, 2007, 4:14 AM
AlanPosted Nov 28, 2007, 9:40 AM
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;