码迷,mamicode.com
首页 > Windows程序 > 详细

C#中遍历ArrayList的三种方法

时间:2018-11-08 16:12:30      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:ace   add   main   next   string   current   rgs   pac   dem   

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

        }

    }

}

C#中遍历ArrayList的三种方法

标签:ace   add   main   next   string   current   rgs   pac   dem   

原文地址:https://www.cnblogs.com/remember-forget/p/9929189.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!