Skip to main content

C# ArrayList

C# ArrayList is used when there is a need for variable size array:

using System;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList List1 = new ArrayList();
            ArrayList List2 = new ArrayList();
            List1.Add("B");
            List1.Add("A");
            List1.Add("C");
            Console.WriteLine("Shows Added valuess");
            ShowArray(List1);
            //insert 
            List1.Insert(3, "D");
            //sort ms in an arraylist
            List1.Sort();
            ShowArray(List1);
            //remove 
            List1.Remove("B");
            //remove from a specified index
            List1.RemoveAt(1);
            Console.WriteLine("Shows final values in the ArrayList");
            ShowArray(List1);

            //Add one ArrayList to second one
            List2.Add("X");
            List2.Add("Y");
            List2.Add("Z");

            List1.AddRange(List2);
            ShowArray(List1);

            //RemoveRange
            List1.RemoveRange(1, 3);
            ShowArray(List1);

            //foreach
            foreach ( string Value in List2)
            {
                Console.WriteLine(Value);
            }

            Console.ReadLine();

        }
        public static void ShowArray(ArrayList anArray)
        {
            int i;
            for (i = 0; i <= anArray.Count - 1; i++)
            {
                Console.WriteLine(anArray[i].ToString());
            }
            Console.ReadLine();
        }

    }
}




Comments

Popular posts from this blog

Problem with encoding Arabic with Google Chrome on Windows 10: Text not being displayed properly

تصحيح مشكلة قرائة اللغه العربيه على جوجل كروم If you have issue of text not being displayed properly in Chrome on Windows 10, you need to flow the steps below: In the browser address bar go to the Chrome flags settings by going to the following address: chrome://flags/#disable-direct-write. Change the "Disable DirectWrite Windows" from Enable to Disable. Click on "RELAUNCH NOW"!