Archive for October, 2009

Laziness in C# 4.0 – Lazy<T>

Posted: October 4, 2009 in .NET, C#
Tags: , ,

Lazy Instantiation” defers creation of an object till the time it is actually accessed.The process of object creation is always expensive as it involves allocation of memory on the heap.So Lazy Instantiation optimizes resources by using them when it is actually required.Till C# 3.0 we needed to some custom coding to implement “Lazy Instantiation” pattern.Now C# 4.0 introduces the Lazy<T> class as part of BCL for this purpose.In this post we will take a detailed look into the behavior and functioning of this class.

(more…)

Advertisements