public sealed class SampleProgram
{
static readonly SampleProgram _instance;
public static readonly SampleProgram Instance
{
if (_instance == null)
{
_instance = new SampleProgram();
}
return _instance;
}
SampleProgram()
{
}
}
Optimized singleton
public sealed class SampleProgram
{
static readonly SampleProgram _instance = new SampleProgram();
public static readonly SampleProgram Instance
{
get
{
return _instance;
}
}
SampleProgram()
{
}
}
Optimized singleton is much faster than NullcheckSingleton Have a look on the above example and as i am discussed in my previous thread about the time comparison in both singleton pattern.
[Reference Jon Skeet's thorough singleton page.]
0 comments:
Post a Comment