using System; using System.Collections; using System.Linq; using System.Text;
namespace ArrayListDemo { class Program { static void Main(string[] args) { ArrayList arr = new ArrayList(); arr.Add("How"); arr.Add("are"); arr.Add("you"); arr.Add(100); arr.Add(200); arr.Add(300); arr.Add(1.2); arr.Add(22.8); //第一种遍历ArrayList的方法 Console.WriteLine("第一种遍历ArrayList的方法:"); for (int i = 0; i < arr.Count; i++) { Console.Write(arr[i].ToString()+" "); } // Console.Read(); //第二种遍历ArrayList的方法: Console.WriteLine("/n第二种遍历ArrayList的方法:"); foreach (object o in arr) { Console.Write(o.ToString() + " "); } //Console.Read();
//第 三种遍历 ArrayList 对象的方法 Console.WriteLine("/n第三种遍历ArrayList的方法:"); IEnumerator ie=arr.GetEnumerator(); while(ie.MoveNext()) { Console.Write(ie.Current.ToString()+" "); } Console.Read(); } } }
运行结果如下:
|
|