什么是C#收益回报? [英] What is yield return in C#?

查看:104
本文介绍了什么是C#收益回报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:

什么是在C#中使用yield关键字?

我最近注意到了收益的关键字,这引起了我的注意。英语不是我的主要语言,以便一词的含义本身可以躲避我的。这是什么关键字在C#中的意思,它是如何使用的?

I've recently noticed the "yield" keyword and it caught my attention. English is not my primary language so the meaning of the word itself may elude me as well. What does that keyword mean in C# and how is it used?

推荐答案

收益在C#中的迭代器方法使用的上下文关键字。基本上,它有两个用例:

yield is a contextual keyword used in iterator methods in C#. Basically, it has two use cases:


  • 收益回报的obj; 返回下一个序列中的项目

  • 产量突破; 停止返回序列的元素(如果控制到达iterator方法体的末尾自动发生这种情况)。

  • yield return obj; returns the next item in the sequence.
  • yield break; stops returning sequence elements (this happens automatically if control reaches the end of the iterator method body).

这篇关于什么是C#收益回报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆