patterncsharpCritical
When should I use Lazy<T>?
Viewed 0 times
shouldlazyusewhen
Problem
I found this article about
Can someone point me to a practical use of the
Lazy: Laziness in C# 4.0 – LazyCan someone point me to a practical use of the
Lazy class in a real application? In other words, when should I use it?Solution
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.
Usually this is preferable when the object may or may not be used and the cost of constructing it is non-trivial.
Usually this is preferable when the object may or may not be used and the cost of constructing it is non-trivial.
Context
Stack Overflow Q#6847721, score: 306
Revisions (0)
No revisions yet.