在C#延迟执行和懒惰的评价之间的区别 [英] Difference between deferred execution and Lazy evaluation in C#

查看:202
本文介绍了在C#延迟执行和懒惰的评价之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否请你让我知道什么是C#延迟执行和懒惰评估之间的确切尊重?这两个是用来synonymously.Could有人请解释一个例子??


的区别< DIV CLASS =h2_lin>解决方案

在实践中,他们的意思是本质上是一回事。然而,这是最好使用术语的延迟




  • 手段的不这样做的工作,直到你绝对必须的。


  • 延迟办法不,直到主叫实际使用它计算出结果。




在实践中,当主叫用户决定使用评估结果(即开始通过的IEnumerable<迭代; T> ),这恰恰是在该点的工作需要完成(如发出查询到数据库)。



术语延迟更具体的/描述性的,以什么实际发生的。当我说我的的,这意味着我的避免做不必要的工作的;它的模棱两可,以什么的真正的暗示。然而,当我说,执行/评估的延迟的,这基本上意味着,我不给你真正的结果可言,而是一个的票,你可以用它来认领结果。我的延迟的居然走出去的获得的这一结果,直到你的要求的吧。



请使用术语的推迟讨论这个问题的时候,因为它涉及到C#的。的的是一个模糊的版本



注意:懒的执行/评估的不同从慵懒的加载的中的的背景下。 延迟加载预先加载是用于描述如何序列的元素加载项。当一个序列加载的懒惰地的,这意味着任何正在生成序列不只是足够的工作负载的在时间的一个元素。当一个序列的热切的加载,整个的序列被加载一次全部并存储在本地缓冲器。不同的使用要求,需要不同的装载方式。


Could you please let me know what is the exact deference between deferred execution and Lazy evaluation in C#?These two are used synonymously.Could some one please explain the difference with an example??

解决方案

In practice, they mean essentially the same thing. However, it's preferable to use the term deferred.

  • Lazy means "don't do the work until you absolutely have to."

  • Deferred means "don't compute the result until the caller actually uses it."

In practice, when the caller decides to use the result of an evaluation (i.e. start iterating through an IEnumerable<T>), that is precisely the point at which the "work" needs to be done (such as issuing a query to the database).

The term deferred is more specific/descriptive as to what's actually going on. When I say that I am lazy, it means that I avoid doing unnecessary work; it's ambiguous as to what that really implies. However, when I say that execution/evaluation is deferred, it essentially means that I am not giving you the real result at all, but rather a ticket you can use to claim the result. I defer actually going out and getting that result until you claim it.

Please use the term deferred when discussing the subject as it pertains to C#. Lazy is a vaguer version.

Note: Lazy execution/evaluation is different from lazy loading or fetching in the context of a sequence. Lazy loading and eager loading are terms used to describe how elements of a sequence are loaded. When a sequence is loaded lazily, it means that whatever is generating the sequence does just enough work to load one element at a time. When a sequence is eagerly loaded, the entire sequence is loaded all at once and stored in a local buffer. Different usage requirements call for different loading patterns.

这篇关于在C#延迟执行和懒惰的评价之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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