I have found a code snippet that we can use for a singleton instance of a class in C#.
Here is the code:
public sealed class Singleton
{
private static Singleton instance = null;
private static readonly object padlock = new object();
Singleton()
{
}
public static Singleton Instance
{
get
{
lock (padlock)
{
if (instance == null)
{
instance = new Singleton();
}
return instance;
}
}
}
}
I have to create a generic singleton instance that I can use for any type of class. But that generic method should have one instance for one type.