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.
xxxxxxxxxx
1
using System;
2
using System.Collections;
3
4
namespace Test
5
{
6
class Program
7
{
8
static void Main(string[] args)
9
{
10
ArrayList list = new ArrayList();
11
12
for (int i = 0; i < 10; ++i)
13
list.Add(i);
14
15
foreach (int entry in list)
16
Console.WriteLine(entry);
17
18
list.Clear();
19
}
20
}
21
}
Output:
xxxxxxxxxx
1
0
2
1
3
2
4
3
5
4
6
5
7
6
8
7
9
8
10
9
xxxxxxxxxx
1
using System;
2
using System.Collections.Generic;
3
4
namespace Test
5
{
6
class Program
7
{
8
static void Main(string[] args)
9
{
10
List<int> list = new List<int>();
11
12
for(int i = 0; i < 10; ++i)
13
list.Add(i);
14
15
foreach (int entry in list)
16
Console.WriteLine(entry);
17
18
list.Clear();
19
}
20
}
21
}
Output:
xxxxxxxxxx
1
0
2
1
3
2
4
3
5
4
6
5
7
6
8
7
9
8
10
9