static IEnumerable<int> WithNoYield()
{
IList<int> list = new List<int>();
for (int i = 0; i < 20; i++)
{
Console.WriteLine(i.ToString());
if(i > 2)
list.Add(i);
}
return list;
}
static IEnumerable<int> WithYield()
{
for (int i = 0; i < 20; i++)
{
Console.WriteLine(i.ToString());
if(i > 2)
yield return i;
}
}
.method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 1
.locals init (
[0] int32 i,
[1] class [mscorlib]System.Collections.Generic.IEnumerator`1<int32> CS$5$0000)
L_0000: call class [mscorlib]System.Collections.Generic.IEnumerable`1<int32> TestLambda.Program::WithYield()
L_0005: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1<!0> [mscorlib]System.Collections.Generic.IEnumerable`1<int32>::GetEnumerator()
L_000a: stloc.1
L_000b: br.s L_0020
L_000d: ldloc.1
L_000e: callvirt instance !0 [mscorlib]System.Collections.Generic.IEnumerator`1<int32>::get_Current()
L_0013: stloc.0
L_0014: ldloca.s i
L_0016: call instance string [mscorlib]System.Int32::ToString()
L_001b: call void [mscorlib]System.Console::WriteLine(string)
L_0020: ldloc.1
L_0021: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext()
L_0026: brtrue.s L_000d
L_0028: leave.s L_0034
L_002a: ldloc.1
L_002b: brfalse.s L_0033
L_002d: ldloc.1
L_002e: callvirt instance void [mscorlib]System.IDisposable::Dispose()
L_0033: endfinally
L_0034: call string [mscorlib]System.Console::ReadLine()
L_0039: pop
L_003a: ret
.try L_000b to L_002a finally handler L_002a to L_0034
}
private bool MoveNext()
{
switch (this.<>1__state)
{
case 0:
this.<>1__state = -1;
this.<i>5__1 = 0;
goto Label_006A;
case 1:
this.<>1__state = -1;
goto Label_005C;
default:
goto Label_0074;
}
Label_005C:
this.<i>5__1++;
Label_006A:
if (this.<i>5__1 < 20)
{
Console.WriteLine(this.<i>5__1.ToString());
if (this.<i>5__1 > 2)
{
this.<>2__current = this.<i>5__1;
this.<>1__state = 1;
return true;
}
goto Label_005C;
}
Label_0074:
return false;
}
var result = from book in books
where book.Title.StartWiths(“t”)
select book
if(state > 0)
{
foreach(var item in result)
{
//….
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有