Using Lazy class in C#

gpeipman
14.6K views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Using Lazy class in C#

System namespace in .NET Framework has Lazy class that provides us with basic mechanism for lazy loads. The idea of Lazy class is simple - initialize class with action that builds or gets lazy loaded value and when value is asked then run the action if lazy loading is not happened yet.

To demonstrate Lazy class let's see the example I created once. Before running the code, go through it and try to figure out in what order messages will appear.

References

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content