什么是收益率?什么是asp.net使用产量benifit? [英] What is yield?, and what is the benifit to use yield in asp.net?

查看:207
本文介绍了什么是收益率?什么是asp.net使用产量benifit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能帮助我在收益关键字的理解 asp.net(C#)

can you help me in understanding of yield keyword in asp.net(C#).

推荐答案

收益回报将自动为您创建一个枚举。

Yield return automatically creates an enumerator for you.

<一个href=\"http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx\">http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx

所以,你可以做这样的事情。

So you can do something like

//pseudo code:

while(get_next_record_from_database)
{
  yield return your_next_record;
}

它可以让你快速创建一个对象集合(一个枚举),您可以通过循环和检索记录。 yield return语句处理所有为您创建一个枚举器所需的code的。

It allows you to quickly create an object collection (an Enumerator) that you can loop through and retrieve records. The yield return statement handles all the of the code needed to create an enumerator for you.

yield return语句的很大一部分是,你不必加载所有的集合中的项目的集合返回给调用方法之前。它允许集合延迟加载,所以你不交罚款的访问一次全部。

The big part of the yield return statement is that you don't have to load all the of the items in a collection before returning the collection to the calling method. It allows lazy loading of the collection, so you don't pay the access penalty all at once.

在使用产量返回

这篇关于什么是收益率?什么是asp.net使用产量benifit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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