Maha

Maha

  • NA
  • 0
  • 324.6k

ArrayList in C#

Jun 29 2007 6:07 PM
June 29, 2007

Hi Guys

I got the following program from a website. Website address is given below. I wish to know what else can be used to replace the "Add" word. Please help me.

myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!");

Thank you

//http://msdn2.microsoft.com/en-us/library/system.collections.arraylist.aspx

using System;
using System.Collections;

public class SamplesArrayList 
{
  public static void Main() 
  {
  // Creates and initializes a new ArrayList.
  ArrayList myAL = new ArrayList();
  myAL.Add("Hello");
  myAL.Add("World");
  myAL.Add("!");

  // Displays the properties and values of the ArrayList.
  Console.WriteLine( "myAL" );
  Console.WriteLine( "  Count:  {0}", myAL.Count );
  Console.WriteLine( "  Capacity: {0}", myAL.Capacity );
  Console.Write( "  Values:" );
  PrintValues( myAL );
  }

  public static void PrintValues( IEnumerable myList ) 
  {
  foreach ( Object obj in myList )
  Console.Write( "  {0}", obj );
  Console.WriteLine();
  }
}

Answers (4)