Add Items Dynamically to .NET Arrays with C#

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);
}


Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Related Posts

Tags: , ,

Leave a Reply





Donate

If you found this article useful and would like to see more like it this please consider making a donation.