EN
C#/.NET - ArrayList vs List<T> in C#
12
points
In C#/.NET System.Collections.Generic.List
is generic implementation of System.Collections.ArrayList
. Second one is obsolete and not recommended to use.
1. ArrayList
class example
using System;
using System.Collections;
namespace Test
{
class Program
{
static void Main(string[] args)
{
ArrayList list = new ArrayList();
for (int i = 0; i < 10; ++i)
list.Add(i);
foreach (int entry in list)
Console.WriteLine(entry);
list.Clear();
}
}
}
Output:
0
1
2
3
4
5
6
7
8
9
2. List<T>
class example
using System;
using System.Collections.Generic;
namespace Test
{
class Program
{
static void Main(string[] args)
{
List<int> list = new List<int>();
for(int i = 0; i < 10; ++i)
list.Add(i);
foreach (int entry in list)
Console.WriteLine(entry);
list.Clear();
}
}
}
Output:
0
1
2
3
4
5
6
7
8
9