==========================================================

yield关健字

 

 var q = GetNums(5);

  public static IEnumerable GetNums(int nums)
        {
            int result = 0;

            for (int i = 0; i < nums; i++)
            {
                result = i;
                yield return result;

            }
        }

结果输出0,1,2,3,4五个数

msdn

 

下面的示例演示两种形式的 yield 语句。

yield return <expression>;
yield break;

============================================================

键字

 static void Method(ref int i)
        {
            // Rest the mouse pointer over i to verify that it is an int.
            // The following statement would cause a compiler error if i
            // were boxed as an object.
            i = i + 44;
        }

        static void Main()
        {
            int val = 1;
            Method(ref val);
            Console.WriteLine(val);

            // Output: 45
        }

===================================================================================

out 键字

 

 

 

    static void Method(out int i)
    {
        i = 44;
    }
    static void Main()
    {
        int value;
        Method(out value);
        // value is now 44
    }

相关文章:

  • 2021-11-16
  • 2022-01-07
  • 2021-06-05
  • 2022-02-04
猜你喜欢
  • 2021-11-23
  • 2022-01-13
  • 2021-09-07
  • 2021-12-10
  • 2022-01-27
  • 2022-12-23
  • 2021-11-03
相关资源
相似解决方案