Unity初识之 yield 与 IEnumerator
2018-02-24 15:56
288 查看
IEnumerator 使用
https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerable?view=netframework-4.7.1
c#文档解释
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/yield
yield关键字出现在迭代器中
使用的两种情况
yield return ;
yield break;
个人理解是,如果是自定义的类型,foreach遍历中要获取迭代器,必须实现IEnumerable接口,要想获得迭代器,就得实现GetEnumerator方法,并且必须实现Ienumerator接口中的MoveNext 和Reset方法。在c#2.0中,引入yield关键字,来返回一个Ienumerator类型。
https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerable?view=netframework-4.7.1
c#文档解释
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/yield
yield关键字出现在迭代器中
使用的两种情况
yield return ;
yield break;
个人理解是,如果是自定义的类型,foreach遍历中要获取迭代器,必须实现IEnumerable接口,要想获得迭代器,就得实现GetEnumerator方法,并且必须实现Ienumerator接口中的MoveNext 和Reset方法。在c#2.0中,引入yield关键字,来返回一个Ienumerator类型。
相关文章推荐
- Unity Editor 编辑器扩展三 Unity Editor 数据持久化及Editor窗口的初识
- IEnumerator、yield及unity3d协程的手动驱动与合并
- Unity初识之 start 和 awake 的区别
- C#中的IEnumerator、foreach、yield
- IEnumerable、IEnumerator与yield的学习
- 创建一个Unity项目,初识Unity面板功能
- unity3D游戏开发一之初识unity
- unity 初识之audio mixer初使用
- 关于unity中使用yield return newWaitForSeconds()后面语句不执行
- Unity初识之代码中跟editor中属性的显示控制
- unity初识之IL ,CIL
- unity初识之添加 gameobjectpool 对象池
- 【使用Unity开发Windows Phone上的2D游戏】(2)初识工具
- unity 3d yield 用法总结
- unity初识之skin
- 【unity】简要分析yield及协同程序的用法
- unity初识之shader 工具
- Unity学习笔记(4) --- Unity的界面排版:初识GUI
- Unity学习笔记(3) --- Unity的界面排版:初识GUILayout
- Unity初识之打包错误