The Startup
Published in

The Startup

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…

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matt Eland

I help people love writing code through writing, speaking, and teaching on Software Engineering & Data Science