Bind arrays and lists to ListBoxes to easily display their items in C#

// Display data in the ListBoxes.Download example
private void Form1_Load(object sender, EventArgs e)
{
string[] animal_array = { "ape", "bear", "cat", "dolphin", "eagle", "fox", "giraffe" };
List<string> animal_list = new List<string>();
animal_list.Add("ape");
animal_list.Add("bear");
animal_list.Add("cat");
animal_list.Add("dolphin");
animal_list.Add("eagle");
animal_list.Add("fox");
animal_list.Add("giraffe");
lstArray.DataSource = animal_array;
lstCollection.DataSource = animal_list;
}
-->
List animal_list = new List();
should be
List animal_list = new List();
May be Type not mentioned for users to figure it out. :)
Reply to this
Sorry about that. The blog gets confused if the the code contains pointy brackets and this code included <string>. I've fixed it now. Thanks for pointing this out!
Reply to this