c# - yield
来源:互联网 发布:linux黑客系统 编辑:程序博客网 时间:2024/05/17 03:44
yield关键字可以概括为一句话:对于返回值为集合的函数,使用yield return,可以每次返回集合中一个元素。
namespace YieldTest{ using System; using System.Collections.Generic; class Program { static void Main(string[] args) { // Call getter Console.WriteLine("----Results of Get():"); foreach (var item in YieldTest.A) { Console.WriteLine(item); } // Call method Console.WriteLine("----Results of Power():"); foreach(var result in YieldTest.Power(2, 10)) { Console.WriteLine(result); } } } public class YieldTest { // Yield in Getter. public static IEnumerable<string> A { get { yield return "Hello"; yield return "World"; yield return "I'm"; yield return "Yield"; } } // Yield in method. public static IEnumerable<int> Power(int x, int exponent) { int result = 1; for (int i = 0; i < exponent; i++) { result = result * x; yield return result; } } }}
0 0
- C# yield
- C# - yield
- c# yield
- C# Yield
- c# - yield
- C# yield
- C# yield
- C#关键字之yield
- C#中的yield关键字
- yield(C# 参考)
- yield(C# 参考)
- C#关键字之yield
- yield(C# 参考)
- C#中的yield return
- C# yield 关键字
- C# yield Statement
- 关键字 yield in C#
- C# yield关键字
- 欢迎使用CSDN-markdown编辑器
- 229,一次性执行代码
- CSS3实现3级动画菜单
- 国内的专业Linux网站(GB)
- 快速使用Python2.7和Django1.9
- c# - yield
- 2016蓝桥杯假期任务之《三部排序》
- c++你不知道的用法之foreach篇
- PLC远程通讯功能集锦(互联网、局域网)(PLC远程监控,PLC远程监视,PLC手机监控)
- Android Button1.图文混排
- Fragment的生命周期
- android 内存优化分析
- jQuery事件之中有其他事件,return 和局部变量无效
- ios 键盘遮挡,监听键盘调整view的frame