2008/03/06

[C#]動態陣列 使用 ArrayList

來源


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();
    }
}

//This code produces output similar to the following:
//myAL
//Count: 3
//Capacity: f
//Values: Hello World !

沒有留言: