Tuesday, March 12, 2019

Lazy initialization in C#

Lazy<T> can be used in C# to delay the initialization of an object. It can be used in singleton architecture as given in the below example.

public static Lazy<MyClass> MyClassInstance = new Lazy<MyClass>(()=> new MyClass());


No comments: