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 smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +756K followers.

Recommended from Medium

CS371p Spring 2021 Entry 2: Dustan Helm

Searching for the RTF Editors: Sϵv϶N and Mach Write

Mikroe Buggy: Obstacle Avoiding Robot

Ops framework for accelerated cloud adoption

Chrome and Bitbucket let me down. (Fixing Bitbucket series — part 1).

GIF of me copying some code from the page, but chrome’s “find” tool says it doesn’t actually appear on the page.

Arduino Uno: PM2.5 sensing revisited

Lightning detection using AS3935 and PIC18F4520 microcontroller

Here’s a fantastic treat for all our Vstmex users! We will regularly conduct LIVE videos on

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

Matt Eland

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

More from Medium

Dot Net library compatibility with Core and Framework

How To Fully Cover I/O File Based Applications in .NET C# With Unit Tests

How to achieve 100% coverage of I/O file based applications in DotNet (.NET) CSharp (C#) Test Driven Development (TDD). Best Practice Code Coding Programming Software Development Architecture Engineering

C# Understanding Interfaces + simple mocking + testing (xUnit + NSubstitute)

【C#】Behavioral Patterns Strategy Mode