zoukankan      html  css  js  c++  java
  • yield 关键字

    第一次遇到,标记一下.

    上段代码应该都明白了怎么用

    public static IEnumerable<T> FindWhere<T>(IEnumerable<T> collection, Predicate<T> predicate)
    {
        if (collection == null)
            throw new ArgumentNullException("collection");
        if (predicate == null)
            throw new ArgumentNullException("predicate");

        foreach (T item in collection) {
            if (predicate(item)) {
                yield return item;
            }
        }
    }

     

    貌似是用于返回对象是IEnumerable或IEnumerable<T>的

  • 相关阅读:
    Pytest学习之 autouse=True,自动调用fixture功能
    Pytest学习之xfail使用
    Pytest学习之use fixtures
    python
    python
    python
    python
    python
    python
    python
  • 原文地址:https://www.cnblogs.com/anders06/p/790416.html
Copyright © 2011-2022 走看看