==========================================================
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
}