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

    namespace ConsoleDemo
    {
      class Program
      {
        static void Main(string[] args)
        {
          string[] str = { "1", "1", "1", "1", "1", "1", "1", "1" };
          var m = getInts(str);
          foreach( var item in m)
          {
            Console.WriteLine(item);
          }
          var m1 = getInts2(str);
          foreach (var item in m1)
          {
            Console.WriteLine(item);
          }
        }
        public static IEnumerable<int> getInts(params string[] strs)
        {
          List<int> results = new List<int>();
          foreach(var item in strs)
          {
            Console.WriteLine(item + "+++++++++");
            results.Add(int.Parse(item));
          }
          return results;
        }
        public static IEnumerable<int> getInts2(params string[] strs)
        {
          foreach (var item in strs)
          {
            Console.WriteLine(item + "----------");
            yield return int.Parse(item);
          }

        }
      }

    }

  • 相关阅读:
    logging模块、sys模块、shelve模块
    re模块、hashlib模块
    包、常用模块
    模块
    迭代器、生成器、递归、二分法
    函数对象、函数嵌套、名称空间与作用域、闭包函数、装饰器
    函数
    文件处理
    字符编码
    Djiango导读
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14082908.html
Copyright © 2011-2022 走看看