加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

C#中使用IEnumerator接口遍历集合

(2007-02-13 11:07:58)
分类: 我与.NET

C#中使用IEnumerator接口遍历集合!

 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList arlist = new ArrayList();
            for (int i = 0; i <= 8; i++)
            {
                arlist.Add(i);
            }
            IEnumerator  enumer = arlist.GetEnumerator(2,5);//这句返回从第二个元素起,找5个元素.结果为 2,3,4,5,6.如果此处换为GetEnumerator(),则返回所有

            while (enumer.MoveNext()) //一定要先movenext,不然会有异常
            {
                Console.WriteLine(enumer.Current.ToString());
            }
            Console.ReadLine();
        }
      
    }
}
很简单....呵呵~~~~~!

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有