Skip to content

Instantly share code, notes, and snippets.

@xepherys
xepherys / SingletonLazyThreadsafe.cs
Created December 8, 2018 17:28
This is a basic threadsafe Singleton. It was meant for me to have quick access to my skeleton Singleton class, but I added comments so that others, including those new to C# might find it useful.
using System;
// Update namespace as needed
namespace WhatsYourName
{
/*
This is the name of your threadsafe Singleton - change "SingletonLazyThreadsafe" to value that makes sense, and be sure to use your
editors [Rename] option, or update all values to match.
Just because the Singleton itself is threadsafe does not mean that all methods that might be contained are automatically threadsafe.