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

Five free tools for managing partitions - TechRepublic

1: MiniTool Partition Wizard Free Edition As its name suggests,  MiniTool Partition Wizard Free Edition  is a free tool for creating and managing partitions. It has a clean interface and does a nice job of providing access to the most common partition-related tasks without being overly complex. 2: EaseUS Partition Master Free Edition EaseUS Partition Master Free Edition  is another free tool for creating and managing partitions. At first glance, it appears to be somewhat lightweight. Upon closer inspection, however, you'll discover that it includes some nice features, such as a disk cloning wizard and a wizard that lets you migrate an OS to an alternate location. 3: AOMEI Partition Assistant Standard Edition AOMEI Partition Assistant Standard Edition  is a free partition management tool. Its interface isn't exactly original. In fact, I had to do a double take to see whether this application was just a reskinned version of one of the other applications discussed in t...

TCP/IP Networking

IPv4 Address Space = 2^32 Address Example: 192.168.1.105 IPv6 Address Space = 2^128 100 IP Addresses for every atom on earth World IPv6 Day June 8, 2011 World IPv6 Launch June 6, 2012 Address Example: fe80::f984:7a81:d6dd:a3e6%19 IPCONFIG examples:      > ipconfig                                   ... Show information     > ipconfig /all                              ... Show detailed information     > ipconfig /renew                        ... renew all adapters     > ipconfig /renew EL*                 ... renew any connection that has its name starting with EL     > ipconfig /release *Con*         ...