Getting Lazy in C#
If you’re anything like me, you’ve looked for ways of making your applications faster. In this article, I’ll show you a somewhat unknown class in the .NET framework that makes lazy creation of objects easy to do and thread-safe.
The Old Way
Before we get to the fun stuff, let’s take a look at how you might try to do these things without .NET’s Lazy<T>
classes.
Typically when you design a class, you might start with code like this:
You might eventually find that as the number of things you need to instantiate…