什么时候应该使用懒惰< T>? [英] When should I use Lazy<T>?

查看:154
本文介绍了什么时候应该使用懒惰< T>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这篇文章关于延迟懒惰在C#4.0 - 懒

I found this article about Lazy: Laziness in C# 4.0 – Lazy

什么是必须使用惰性对象的最佳性能的最佳实践? 有人能指出我在实际应用中实际使用?换句话说,当我应该使用它?

What is the best practice to have best performance using Lazy objects? Can someone point me to a practical use in a real application? In other words, when should I use it?

推荐答案

您通常使用它时,你要实例的东西在第一时间它的实际使用。这将延迟创建它,如果/当它需要总是招致的费用,而不是到的成本。

You typically use it when you want to instantiate something the first time its actually used. This delays the cost of creating it till if/when it's needed instead of always incurring the cost.

通常这是时可以或可以不被使用的对象preferable,构建它的成本也非平凡

Usually this is preferable when the object may or may not be used and the cost of constructing it is non-trivial.

这篇关于什么时候应该使用懒惰< T>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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