Adding to an array
As everyone said, use List in the System.Collections.Generic namespace. You can also use Hashtable, which will allow you to give each row a value or "key", which gives you an easy way to pull out a specific row with a keyword. (as for storing messages stored in memory for whatever purpose). You can also create a new array each time you add a value, make the new array 1 larger than the old one, copy all data from the first array to the second array, and then add the new value to the last slot (length - 1) Then replace the old array with the new one. This is the most manual way to do it. But List and Hashtable work great too.
a source to share
If you need indexing take a look at the data type of the dictionary also in System.Collection
http://msdn.microsoft.com/en-us/library/xfhwa508.aspx
so you can do something like
Dictionary<int, string> dictionary = new Dictionary<int, string>();
dictionary.Add(1, "afljsd");
a source to share
Here's an extension method used to add an array to an array and create a new array of strings
public static class StringArrayExtension
{
public static string[] GetStringArray (this string[] currentArray, string[] arrayToAdd)
{
List<String> list = new List<String>(currentArray);
list.AddRange(arrayToAdd);
return list.ToArray();
}
}
a source to share
You can do this, but I don't recommend:
// Reallocates an array with a new size, and copies the contents
// of the old array to the new array.
// Arguments:
// oldArray the old array, to be reallocated.
// newSize the new array size.
// Returns A new array with the same contents.
public static System.Array ResizeArray (System.Array oldArray, int newSize) {
int oldSize = oldArray.Length;
System.Type elementType = oldArray.GetType().GetElementType();
System.Array newArray = System.Array.CreateInstance(elementType,newSize);
int preserveLength = System.Math.Min(oldSize,newSize);
if (preserveLength > 0)
System.Array.Copy (oldArray,newArray,preserveLength);
return newArray;
}
a source to share