什么时候应该使用懒惰< T>?什么时候、懒惰、GT、LT

由网友(话少又软萌的我)分享简介:我发现这篇文章关于延迟:懒惰在C#4.0 - 懒 I found this article about Lazy: Laziness in C# 4.0 – Lazy什么是必须使用惰性对象的最佳性能的最佳实践?有人能指出我在实际应用中实际使用?换句话说,当我应该使用它?What is the best pra...

我发现这篇文章关于延迟:懒惰在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.

阅读全文

相关推荐

最新文章