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

        }

    }

}

相关文章:

  • 2021-12-09
  • 2022-12-23
  • 2021-11-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2022-01-27
  • 2021-08-22
  • 2021-12-31
相关资源
相似解决方案