I want to create a Singleton for my class, I have the following code, it works fine but is there any potential issue which I am not able to see ?
public class Singleton
{
private static Singleton _singleton;
private Singleton()
{
}
public static Singleton GetInstance()
{
Interlocked.CompareExchange(ref _singleton, new Singleton(), null);
return _singleton;
}
public void SayHello()
{
Console.WriteLine($" Hello from {Thread.CurrentThread.ManagedThreadId}");
}
}