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
VulpesPosted Jun 24, 2013, 3:41 PM
To deal with that just insert the highlighted line:
Arun KurmiPosted Jun 24, 2013, 2:45 PM
This is my full code:
Sanjeeb LenkaPosted Jun 24, 2013, 12:52 PM
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.
VulpesPosted Jun 24, 2013, 12:23 PM
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