Languages
[Edit]
EN

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

12 points
Created by:
Root-ssh
68810

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
Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join