public class Singleton { private static readonly Lazy_instance = new Lazy (()=>new Singleton()); private Singleton() { // function body } public static Singleton Instance { get {return _instance.Value;} } }
public class Person { private LazyHere, the ContactNumber object is created only when the ContactNumber property of the Person object is accessed. The library that contains the Lazy class is part of the Base Class Library (BCL) in the .NET Framework. No additional package or library is required to use it._contactNumber = new Lazy (); public ContactNumber ContactNumber { get { return _contactNumber.Value; } } } public class ContactNumber { // function body }