Singleton Design pattern?How do you achieve it?
Answer Posted / sudhir sheoran
Singleton design pattern can be achieved by following implementation:
1) Make class public
2) Static method to generate the instance of class(calling this method we can get the instance of a class if already a instance is generated we will get the same instance)
3) Private Constructor (so that no other class can generate the instance of singleton class)
Example::
class Class1
{
private static Class1 classInstance;
private IList<int> list = new List<int>();
private Class1()
{
if (list == null)
{
list = new List<int>();
}
}
public static void GetInstance()
{
if (classInstance == null)
{
classInstance = new Class1();
}
}
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Describe how passport authentication works.
What is the difference between ASP.NET Webforms and ASP.NET MVC?
How do you use viewstate?
What is Dynamic Web and discuss its usage with the help of real life examples?
What do you mean by authentication?
Write some code using interfaces, virtual methods, and an abstract class`
What is query string?
1.what is the application pool. 2.what is the HttpModile and Http Handler. 3.C# 3.0 Features ? 4.Anonoymous Type,methopd and claas in 3.0? 5.difference between statsic and const ? 6.session vs application 7.state management clint side and server side ? 8.Genric list 9.c# 3.0 vs 3.5
What is localhost in asp.net?
What is special types forms
Tell me how asp.net mvc differs from asp.net web forms? : asp.net mvc
In order to get assembly info which namespace we should import?
What is query string with example?
If I have more than one version of one assemblies, then how will I use old version (how/where to specify version number?) In my application?
ASP.NET 2.0's new membership API used for creating and managing user account is exposed through which 2 clause?