Goldman Sachs Interview Question
Software Engineer / DevelopersHere is the sample C# code for Singleton Class
public sealed class Singleton
{
static readonly Singleton instance=new Singleton();
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static Singleton()
{
}
Singleton()
{
}
public static Singleton Instance
{
get
{
return instance;
}
}
}
singleton pattern is a dedin pattern where you restrict the instantiation of a class to single object. Used when you need exactly one object of the class.
- s October 21, 2010