Hello! In this tutorial we will learn how to use an arraylist in C#. This is a practical tutorial and we will be looking at several arraylist examples.

Example – Simple ArrayList

Let’s look at a hello world of arraylist in c#.

Step 1: Write Code

Add the following code in a .cs file:

using System;
using System.Collections;

namespace ArrayListDemo{

    class App
    {
        static void Main(string[] args)
        {
            ArrayList alist = new ArrayList();
            alist.Add(101);
            alist.Add(202);
            alist.Add(303);
            alist.Add(404);
            alist.Add(505);
            foreach(int i in alist) {
                Console.WriteLine(i);
            }//end of for each

            Console.ReadKey();
        }
    }

}

Step 2: Run

Run the code and you will get the following:

101
202
303
404
505

Categorized in: