反编译后,迭代器用的是状态机,栈本身就是状态机,由于协程本身也有栈, 我怀疑C#中的 迭代器和基于任务的异步编程是协程(未经过验证)

.class nested private auto ansi sealed beforefieldinit '<GetEnumerator>d__12'
extends [System.Runtime]System.Object
implements class [System.Runtime]System.Collections.Generic.IEnumerator`1<object>,
[System.Runtime]System.Collections.IEnumerator,
[System.Runtime]System.IDisposable

//这个位置相当于以上等于 private class  sealed <GetEnumerator>d__12:object,IEnumerator,IEnumerator,IDisposable
// nested :嵌套    
//implements  :实现接口
//extends:是继承父类,只要那个类不是声明为final或者那个类定义为abstract的就能继承,
beforefieldinit:beforefieldinit指示CLI在调用静态方法之前不必初始化类型。


{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
自定义实例:.custom 声明,后跟类型的方法声明 构造函数
CompilerGeneratedAttribute 特性应用到任何应用程序元素,以指示该元素由编译器生成。

// Fields 字段 .field private int32 '<>1__state' .field private object '<>2__current' .field public class School.ClassOfStudent '<>4__this' .field private int32 '<index>5__1' // Methods 
//

.method public hidebysig specialname rtspecialname
instance void .ctor (
int32 '<>1__state'
) cil managed
//cil managed:托管代码
{
.custom instance void [System.Runtime]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = (
01 00 00 00
)
// Method begins at RVA 0x2369
// Code size 15 (0xf)
.maxstack 8 // {
IL_0000: ldarg.0
// (no C# code)
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
// this.<>1__state = <>1__state;
IL_0006: nop
IL_0007: ldarg.0
IL_0008: ldarg.1
IL_0009: stfld int32 School.ClassOfStudent/'<GetEnumerator>d__12'::'<>1__state'
// }
IL_000e: ret
} // end of method '<GetEnumerator>d__12'::.ctor .method private final hidebysig newslot virtual
instance void System.IDisposable.Dispose () cil managed
{
.custom instance void [System.Runtime]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = (
01 00 00 00
)
.override method instance void [System.Runtime]System.IDisposable::Dispose()
// Method begins at RVA 0x2379
// Code size 1 (0x1)
.maxstack 8 // }
IL_0000: ret
} // end of method '<GetEnumerator>d__12'::System.IDisposable.Dispose .method private final hidebysig newslot virtual
instance bool MoveNext () cil managed
{
.override method instance bool [System.Runtime]System.Collections.IEnumerator::MoveNext()
// Method begins at RVA 0x237c
// Code size 133 (0x85)
.maxstack 3
.locals init (
[0] int32,
[1] int32,
[2] bool
) // switch (<>1__state)
IL_0000: ldarg.0
IL_0001: ldfld int32 School.ClassOfStudent/'<GetEnumerator>d__12'::'<>1__state'
IL_0006: stloc.0
// (no C# code)
IL_0007: ldloc.0
IL_0008: brfalse.s IL_0012 IL_000a: br.s IL_000c IL_000c: ldloc.0
IL_000d: ldc.i4.1
IL_000e: beq.s IL_0014 IL_0010: br.s IL_0016 IL_0012: br.s IL_0018 // return false;
IL_0014: br.s IL_004f IL_0016: ldc.i4.0
IL_0017: ret // <>1__state = -1;
IL_0018: ldarg.0
IL_0019: ldc.i4.m1
IL_001a: stfld int32 School.ClassOfStudent/'<GetEnumerator>d__12'::'<>1__state'
// <index>5__1 = 0;
IL_001f: nop
IL_0020: ldarg.0
IL_0021: ldc.i4.0
IL_0022: stfld int32 School.ClassOfStudent/'<GetEnumerator>d__12'::'<index>5__1'
// break;
IL_0027: br.s IL_0067 // <>2__current = <>4__this.students[<index>5__1];
IL_0029: nop
IL_002a: ldarg.0
IL_002b: ldarg.0
IL_002c: ldfld class School.ClassOfStudent School.ClassOfStudent/'<GetEnumerator>d__12'::'<>4__this'
IL_0031: ldfld class [System.Collections]System.Collections.Generic.List`1<class School.Student> School.ClassOfStudent::students
IL_0036: ldarg.0
IL_0037: ldfld int32 School.ClassOfStudent/'<GetEnumerator>d__12'::'<index>5__1'
IL_003c: callvirt instance !0 class [System.Collections]System.Collections.Generic.List`1<class School.Student>::get_Item(int32)
IL_0041: stfld object School.ClassOfStudent/'<GetEnumerator>d__12'::'<>2__current'
// <>1__state = 1;
IL_0046: ldarg.0
IL_0047: ldc.i4.1
IL_0048: stfld int32 School.ClassOfStudent/'<GetEnumerator>d__12'::'<>1__state'
// return true;
IL_004d: ldc.i4.1
IL_004e: ret // <>1__state = -1;
IL_004f: ldarg.0
IL_0050: ldc.i4.m1
IL_0051: stfld int32 School.ClassOfStudent/'<GetEnumerator>d__12'::'<>1__state'
// <index>5__1++;
IL_0056: nop
IL_0057: ldarg.0
IL_0058: ldfld int32 School.ClassOfStudent/'<GetEnumerator>d__12'::'<index>5__1'
IL_005d: stloc.1
// if (<index>5__1 < <>4__this.students.Count)
IL_005e: ldarg.0
IL_005f: ldloc.1
IL_0060: ldc.i4.1
IL_0061: add
IL_0062: stfld int32 School.ClassOfStudent/'<GetEnumerator>d__12'::'<index>5__1' IL_0067: ldarg.0
IL_0068: ldfld int32 School.ClassOfStudent/'<GetEnumerator>d__12'::'<index>5__1'
IL_006d: ldarg.0
IL_006e: ldfld class School.ClassOfStudent School.ClassOfStudent/'<GetEnumerator>d__12'::'<>4__this'
IL_0073: ldfld class [System.Collections]System.Collections.Generic.List`1<class School.Student> School.ClassOfStudent::students
IL_0078: callvirt instance int32 class [System.Collections]System.Collections.Generic.List`1<class School.Student>::get_Count()
IL_007d: clt
IL_007f: stloc.2
IL_0080: ldloc.2
IL_0081: brtrue.s IL_0029 // return false;
IL_0083: ldc.i4.0
IL_0084: ret
} // end of method '<GetEnumerator>d__12'::MoveNext .method private final hidebysig specialname newslot virtual
instance object 'System.Collections.Generic.IEnumerator<System.Object>.get_Current' () cil managed
{
.custom instance void [System.Runtime]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = (
01 00 00 00
)
.override method instance !0 class [System.Runtime]System.Collections.Generic.IEnumerator`1<object>::get_Current()
// Method begins at RVA 0x240d
// Code size 7 (0x7)
.maxstack 8 // return <>2__current;
IL_0000: ldarg.0
IL_0001: ldfld object School.ClassOfStudent/'<GetEnumerator>d__12'::'<>2__current'
IL_0006: ret
} // end of method '<GetEnumerator>d__12'::'System.Collections.Generic.IEnumerator<System.Object>.get_Current' .method private final hidebysig newslot virtual
instance void System.Collections.IEnumerator.Reset () cil managed
{
.custom instance void [System.Runtime]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = (
01 00 00 00
)
.override method instance void [System.Runtime]System.Collections.IEnumerator::Reset()
// Method begins at RVA 0x2415
// Code size 6 (0x6)
.maxstack 8 // throw new NotSupportedException();
IL_0000: newobj instance void [System.Runtime]System.NotSupportedException::.ctor()
IL_0005: throw
} // end of method '<GetEnumerator>d__12'::System.Collections.IEnumerator.Reset .method private final hidebysig specialname newslot virtual
instance object System.Collections.IEnumerator.get_Current () cil managed
{
.custom instance void [System.Runtime]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = (
01 00 00 00
)
.override method instance object [System.Runtime]System.Collections.IEnumerator::get_Current()
// Method begins at RVA 0x241c
// Code size 7 (0x7)
.maxstack 8 // return <>2__current;
IL_0000: ldarg.0
IL_0001: ldfld object School.ClassOfStudent/'<GetEnumerator>d__12'::'<>2__current'
IL_0006: ret
} // end of method '<GetEnumerator>d__12'::System.Collections.IEnumerator.get_Current // Properties
.property instance object 'System.Collections.Generic.IEnumerator<System.Object>.Current'()
{
.get instance object School.ClassOfStudent/'<GetEnumerator>d__12'::'System.Collections.Generic.IEnumerator<System.Object>.get_Current'()
}
.property instance object System.Collections.IEnumerator.Current()
{
.get instance object School.ClassOfStudent/'<GetEnumerator>d__12'::System.Collections.IEnumerator.get_Current()
} } // end of class <GetEnumerator>d__12

yield return Il代码讲解的更多相关文章

  1. 可惜Java中没有yield return

    项目中一个消息推送需求,推送的用户数几百万,用户清单很简单就是一个txt文件,是由hadoop计算出来的.格式大概如下: uid caller 123456 12345678901 789101 12 ...

  2. 读懂IL代码就这么简单 (一)

    一前言 感谢 @冰麟轻武 指出文章的错误之处,现已更正 对于IL代码没了解之前总感觉很神奇,初一看完全不知所云,只听高手们说,了解IL代码你能更加清楚的知道你的代码是如何运行相互调用的,此言一出不明觉 ...

  3. 读懂IL代码就这么简单

    原文地址:http://www.cnblogs.com/zery/p/3366175.html 一前言 感谢 @冰麟轻武 指出文章的错误之处,现已更正 对于IL代码没了解之前总感觉很神奇,初一看完全不 ...

  4. 读懂IL代码(二)

    上一篇提到了最基本的IL代码,应该是比较通俗易懂的,所以有了上一篇的基础之后,这篇便要深入一点点的来讲述了. 首先我必须再来说一些重要的概念: Evaluation Stack(评估栈):这是由.NE ...

  5. 【转载】读懂IL代码就这么简单 (一)

    一前言 感谢 @冰麟轻武 指出文章的错误之处,现已更正 对于IL代码没了解之前总感觉很神奇,初一看完全不知所云,只听高手们说,了解IL代码你能更加清楚的知道你的代码是如何运行相互调用的,此言一出不明觉 ...

  6. C# yield return 原理探究

    天需要些一个小工具,需要使用到多线程读写程序集,接口方法返回值类型需要为"IEnumerable<string>"这里用到了"yield return&quo ...

  7. C#中的using和yield return混合使用

    最近写代码为了为了省事儿用了几个yield return,因为我不想New一个List<T>或者T[]对象再往里放元素,就直接返回IEnumerable<T>了.我的代码里还有 ...

  8. 读懂IL代码就这么简单(三)完结篇

    一 前言 写了两篇关于IL指令相关的文章,分别把值类型与引用类型在 堆与栈上的操作区别详细的写了一遍 这第三篇也是最后一篇,之所以到第三篇就结束了,是因为以我现在的层次,能理解到的都写完了,而且个人认 ...

  9. 读懂IL代码就这么简单(二)

    一 前言 IL系列 第一篇写完后 得到高人指点,及时更正了文章中的错误,也使得我写这篇文章时更加谨慎,自己在了解相关知识点时,也更为细致.个人觉得既然做为文章写出来,就一定要保证比较高的质量,和正确率 ...

随机推荐

  1. js整体

    1.引入 <script type="text/javascript"> 2.输出 使用 window.alert() 写入警告框  使用 document.write ...

  2. .Net Core中自定义认证实现

    一.起因 最近项目中需要对项目同时支持JWT认证,以及自定义的认证校验方式认证.通过对官方文档了解,得到认证实现主要通过继承IAuthenticationHandler 或 Authenticatio ...

  3. java 坐标练习

    定义一个三维空间的点,有三个坐标 实现以下目标: 1.可以生成特定坐标的点对象 2.提供可以设置三个坐标的方法 3.提供可以计算该点到特定点距离的平方的方法 class Point { double ...

  4. iGear 用了这个小魔法,模型训练速度提升 300%

    一个高精度AI模型离不开大量的优质数据集,这些数据集往往由标注结果文件和海量的图片组成.在数据量比较大的情况下,模型训练周期也会相应加长.那么有什么加快训练速度的好方法呢? 壕气的老板第一时间想到的通 ...

  5. python项目中 ,open() 方法, 如何读取json文件的位置。

    一 copy 目标文件绝对路径的URL. 固定在你电脑上的路径.简单好用.

  6. django之定义统一返回数据格式与GET/POST装饰器

    1. 为了返回给网页前端的格式统一,定义一个通用的插件类,返回统一格式数据 # enconding:utf-8 """ 定义一个插件类, ""&quo ...

  7. Lesson6——Pandas Pandas描述性统计

    1 简介 描述统计学(descriptive statistics)是一门统计学领域的学科,主要研究如何取得反映客观现象的数据,并以图表形式对所搜集的数据进行处理和显示,最终对数据的规律.特征做出综合 ...

  8. JAVA 变量的概述

    变量的概述         用于存储可变数据的容器. 变量存在的意义 计算机主要用于处理生活中的数据,由于生活中存在大量的可变数据,那么计算机就必须具备存储可变数据的能力. 比如: 1.时间每一秒都在 ...

  9. mapTest

    import java.util.*;public class mapTest { public static void main(String[] args) throws Exception{ L ...

  10. Haproxy LVS Nginx的优缺点总结

    Haproxy  LVS  Nginx的优缺点总结 1.haproxy优点 2.Nginx优点 3.Nginx缺点 4.LVS优点 5.LVS缺点 haproxy优点: haproxy也是支持虚拟主机 ...