I've been experimenting with that a bit.
Just run some small tests with what you want to do, and use this:
CODE
DateTime starttime = DateTime.Now;
//add code
DateTime endtime = DateTime.Now;
TimeSpan time = endtime - starttime;
Console.WriteLine(time);//or some other way to display it
Some things I've found is that a normal array is much quicker than List<T> when you constantly need to change values of a set of data you know the size of, but when you dont know the size of your dataset List<T> wins since you need to constantly need to copy the array to a new array with the added data etc. And the c# book I have said to chose List<t> over arraylist since it's faster, although I haven't tested it yet. So to be short, it depends on the situation, but feel free to experiment a bit.
To give you some results: here I added 100.000 int values to an array, and a List<int>, and then redid that 100.000 times.
CODE
static void Main(string[] args)
{
DateTime starttijd = DateTime.Now;
int[] i_array = new int[100000];
for (int i = 0; i < 100000; i++)
{
for (int j = 0; j < 100000; j++)
{
i_array[j] = j;
}
}
DateTime eindtijd = DateTime.Now;
TimeSpan tijd = eindtijd - starttijd;
Console.WriteLine(tijd);
starttijd = DateTime.Now;
List<int> i_list = new List<int>();
for (int i = 0; i < 100000; i++)
{
i_list.Clear();
for (int j = 0; j < 100000; j++)
{
i_list.Add(j);
}
}
eindtijd = DateTime.Now;
tijd = eindtijd - starttijd;
Console.WriteLine(tijd);
}
The results on my laptop are: about 10 seconds for the array, about 50 seconds for the list. So in this type of situation where you know exactly in advance how much data you will have, array clearly wins. But in another project, where I didn't know that, the List won.
This post has been edited by Renagado: 2 Jul, 2009 - 02:34 PM