ArrayList Learn programming C#

Lesson:

Dynamic Memory Management


Exercise:

ArrayList


Objetive:

Create a string list using the ArrayList class that already exists in the .NET platform.

Once created, display all the items stored in the list. Insert a new item in the second place of the list, and then display all the items again to check if the insertion was done correctly.


Code:

using System;
using System.Collections;
namespace List
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList miLista = new ArrayList();
            miLista.Add("Hola,");
            miLista.Add("soy");
            miLista.Add("yo");
            foreach (string frase in miLista)
                Console.WriteLine(frase);
            miLista.Insert(1, "Como estas?");
        }
    }
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.