Mid From PDF Coding Scenarios C# Coding Interview

Thread-safe Singleton (Best Practice)?

public sealed class Singleton
{
private static readonly object lockObj = new object();
private static Singleton instance;
private Singleton() { }
public static Singleton Instance
{

get

{
if (instance == null)
{

lock (lockObj)

{
if (instance == null)
instance = new Singleton();
}
}
return instance;
}
}
}

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details