Today I have 2 Questions...
(1)
------------------
ListBox1.Items.Clear(); not work on Generic collection Example.
I have tried 2 example 1)List
2)LinkedList
Code of First Example are:
listBox1.Items.Clear();
//lst.Clear();
for (int i = 0; i < lst.Count; i++)
{
listBox1.Items.Add(lst[i]);
}
private void button1_Click(object sender, EventArgs e)
{
lst.Add("Red");
lst.Add("green");
lst.Add("blue");
lst.Add("pink");
lst.Add("lemon");
LoadMyList();
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
}
___________________________________________________________________
(2)
-----------------
I have seen both List and LinkedList Example but never found any difference in both so questiion are what are the difference in both.If Possible Please gave an Example.
___________________________________________________________________
(2)
-----------------
I have seen both List

VulpesRank #55 · 29.2K reputationPosted Jun 24, 2013, 8:23 AM EDT
Initially, Purple and Magenta are showing in the ListBox but when the button is pressed, they're gone and replaced by Red, green etc.
List
With List
In contrast, LinkedList
As a general rule, stick with List
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jun 24, 2013, 8:52 AM EDT
i take one listbox and two button for test
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default3 : System.Web.UI.Page
{
List
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
ListBox1.Items.Add("Purple");
ListBox1.Items.Add("Magenta");
}
protected void Button2_Click(object sender, EventArgs e)
{
lst.Add("Red");
lst.Add("green");
lst.Add("blue");
lst.Add("pink");
lst.Add("lemon");
LoadMyList();
}
private void LoadMyList()
{
ListBox1.Items.Clear();
//lst.Clear();
for (int i = 0; i < lst.Count; i++)
{
ListBox1.Items.Add(lst[i]);
}
}
}
check on button 1 click it will clear the list box and add the content.
then button2 click it will clear the list box again and list item values.
Arun Kurmi96 reputationPosted Jun 24, 2013, 10:45 AM EDT
This is my full code:
VulpesRank #55 · 29.2K reputationPosted Jun 24, 2013, 11:41 AM EDT
To deal with that just insert the highlighted line: