Back
Close

Using Lazy class in C#

gpeipman
24.6K views

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

Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io