Lazy thread-safe Singleton using LazyT

suggest change

.Net 4.0 type Lazy guarantees thread-safe object initialization, so this type could be used to make Singletons.

public class LazySingleton
{
    private static readonly Lazy<LazySingleton> _instance =
        new Lazy<LazySingleton>(() => new LazySingleton());
 
    public static LazySingleton Instance
    {
        get { return _instance.Value; }
    }

    private LazySingleton() { }
}

Using Lazy<T> will make sure that the object is only instantiated when it is used somewhere in the calling code.

A simple usage will be like:

using System;
                    
public class Program
{
    public static void Main()
    {
        var instance = LazySingleton.Instance;
    }
}

Live Demo on .NET Fiddle

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Singleton Implementation:
* Lazy thread-safe Singleton using LazyT

Table Of Contents
17 Regex
19 Arrays
21 Enum
22 Tuples
24 GUID
27 Looping
36 Casting
42 Singleton Implementation
46 Methods
88 Events
92 Structs
104 Indexer
106 Stream
107 Timers
109 Threading
127 Caching
135 Pointers
147 C# Script