Languages
[Edit]
EN

C#/.NET - ArrayList vs List<T> in C#

12 points
Created by:
Root-ssh
174740

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

3. References

  1. ArrayList Class - Microsoft Docs
  2. List<T> Class - Microsoft Docs
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join