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);
          }

        }
      }

    }

  • 相关阅读:
    python标准库
    python常用标准库
    django-restframework-serializers
    Resources.UnloadUnusedAssets
    Shader 的 Blend
    C++STL queue
    C++STL stack
    C++STL deque
    C++STL容器重点
    C++STL 迭代器
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14082908.html
Copyright © 2011-2022 走看看