首页 > 其他 > 详细

迭代器

时间:2016-03-26 23:54:35      阅读:480      评论:0      收藏:0      [点我收藏+]

创建迭代器最常用的方法是对IEnumerator接口实现GetEnumerator方法。

public class Family : System.Collections.IEnumerable

{

string[] myFamily = {“父亲”,”母亲”,”弟弟”,”妹妹”};

public System.Collections.IEnumerator GetEnumerator()

{

for(int i=0;i<myFamily.Length;i++)

{

yield return myFamily[i];

}

}

}

private void Form_Load(object sender, EventArgs e)

{

Family family = new Family();

foreach(string str in family)

{

 

}

}

 

 

《C#从入门到精通》读后总结

 

迭代器

原文:http://www.cnblogs.com/hmliang/p/5324413.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!