作者:.NET开发
项目:System.Collection
//引入命名空间
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();
}
}
作者:C#程序
项目:System.Collection
//引入命名空间
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
ArrayList baseballTeams = new ArrayList();
baseballTeams.Add("s");
baseballTeams.Add("r");
baseballTeams.Add("F");
foreach (string item in baseballTeams) {
Console.Write(item + "\n");
}
}
}
作者:C#程序
项目:System.Collection
//引入命名空间
using System;
using System.Collections;
class MainClass
{
public static void Main()
{
ArrayList myArrayList = new ArrayList();
myArrayList.Add("This");
myArrayList.Add("is");
myArrayList.Add("a");
myArrayList.Add("test");
ArrayList anotherArrayList = new ArrayList(myArrayList);
Console.WriteLine(anotherArrayList);
}
}