首页 新闻 会员 周边

C#能用foreach遍历访问的对象的要求

0
[已关闭问题] 关闭于 2012-02-02 13:33

需要实现IEnumerable接口或声明GetEnumerator方法的类型。


GetEnumerator方法是使用.是重写?????


using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication24
{
class Program
{
static void Main(string[] args)
{
aa obj = new aa();
foreach (string str in obj)
{

}
}
}
class aa
{
int Current = 0;
public void GetEnumerator()
{ }
}
}


c#
iia的主页 iia | 初学一级 | 园豆:6
提问于:2012-01-27 12:29
< >
分享
所有回答(1)
0

要求必须要实现IEnumerable接口
如果想彻底的了解foreach的原理
我个人觉得必须要从iterator迭代器模式,然后在演化到.NET的IEnumreable和IEnumerator接口上

MR_xiaodan | 园豆:142 (初学一级) | 2012-01-28 16:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册