Add Items Dynamically to .NET Arrays with C#

November 30th, 2008 | Posted in ASP.NET
0

If you are in a situation where you need to add an item to an array you will need to use one of the collection classes such as the Arraylist. New values cannot be added to an array that has set values.

String Array Example

string[] list = new string[] { "one", "two", "three" };

foreach (string item in list)
{
    Response.Write(item);
}

Arraylist Example

Arraylist list = new Arraylist();
list.Add("one");
list.Add("two");
list.Add("three");

foreach (string item in list)
{
    Response.Write(item);
}

Related posts

Leave a Reply