Sunday, June 17, 2007

ASP.NET Dynamic Array

This is one approach to creating a dynamic array in ASP.NET:

public string[] CreateArray()
{
ArrayList myArrayList = new ArrayList();
// Connect to the database and create a data reader (myReader)
while (myReader.Read())
{
// various lines commented out
myArrayList.Add((string) myReader["name"]);
}
return (string[])myArrayList.ToArray(typeof(string));
}

No comments: