会员
众包
新闻
博问
闪存
云市场
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
成了过河卒
博客园
首页
新随笔
联系
订阅
管理
IEnumerable.GetEnumerator 方法的C#例子
下面的代码示例演示如何实现自定义集合的 IEnumerable 接口。在此示例中,没有显式调用但实现了 GetEnumerator,以便支持使用
foreach
(在 Visual Basic 中为
for
each)。此代码示例摘自 IEnumerable 接口的一个更大的示例。
view plaincopy to clipboardprint
?
public
class
People : IEnumerable
{
private
Person[] _people;
public
People(Person[] pArray)
{
_people
=
new
Person[pArray.Length];
for
(
int
i
=
0
; i
<
pArray.Length; i
++
)
{
_people[i]
=
pArray[i];
}
}
public
IEnumerator GetEnumerator()
{
return
new
PeopleEnum(_people);
}
}
posted @
2007-08-11 14:06
过河卒A
阅读(
8139
) 评论(
3
)
编辑
收藏
举报
指间灵动,快码加编
刷新页面
返回顶部
公告