Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you think you have some skills to help others

help someone and become a part of our community - List Q & A

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

0 contributions
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

3. References

  1. ArrayList Class - Microsoft Docs
  2. List<T> Class - Microsoft Docs
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more