ArrayList

In C# ArrayList is a very powerful data structure using which we can assign items of any data type within the same array. Following is an example:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Collections;


namespace ConsoleApplication6
{
    
    class Program
    {
        static void Main(string[] args)
        {
            var list = new ArrayList();

            list.Add(44);
            list.Add("pakistan");
            list.Add(33.676);

            int[] myarray = { 10, 20, 30 };

            list.Add(myarray);

            int l1 = (int)list[0];
            string l2 = (string)list[1];
            double l3 = (double)list[2];
            int[] l4 = (int[])list[3];

            Console.WriteLine(l1);
            Console.WriteLine(l2);
            Console.WriteLine(l3);
            Console.WriteLine(l4[2]);


        }
    }
}

 

Add a Comment

Your email address will not be published. Required fields are marked *