本文整理汇总了C#中System.Collections.ArrayList类的典型用法代码示例。如果您正苦于以下问题:C# ArrayList类的具体用法?C# ArrayList怎么用?C# ArrayList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArrayList类属于System.Collections命名空间,在下文中一共展示了ArrayList类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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();
}
}
输出:
myAL Count: 3 Capacity: 4 Values: Hello World !
示例2: new ArrayList()
//引入命名空间
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");
}
}
}
示例3: new ArrayList(Collection c)
//引入命名空间
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);
}
}