cpetco_andy

导航

C#迭代补充

1.迭代器的返回类型为两种:IEnumerable  、IEnumerator

2.使用yield关键字选择要在foreach循环中使用的值

public static IEnumerable SimpleList() //IEnumerable是返回,SimpleList是迭代器

{

     yield return "string 1";

     yield return "string 2";

     yield return "string 3";

}

posted on 2011-07-28 14:55  cpetco_andy  阅读(118)  评论(0编辑  收藏  举报