星空网 > 软件开发 > ASP.net

迭代器———更锋利的C#代码小记

直接使用yield return关键字通过类似返回值的方式灵活地构造迭代器

迭代器———更锋利的C#代码小记迭代器———更锋利的C#代码小记
 public class EmployeeCollection :IEnumerable<Employee>  {    private Employee[] employees;    #region IEnumerable<Employee>成员    public IEnumerator<Employee> GetEnumerator()    {      foreach(Employee employee in employees)      {        yield return employee;      }    }    #endregion    #region IEnumerable成员    IEnumerator IEnumerable.GetEnumerator()    {      return this.GetEnumerator();    }    #endregion  }

View Code

 




原标题:迭代器———更锋利的C#代码小记

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流