how to implement singelton in C# & its uses?
Answer / chandana
To implement a singleton in C#, the steps are:
1. Make the constructor private
2. Declare a static object of the same class
3. Define a static method which return the same object.
This method checks the static variable object, if it
exists, return the same, if it doesn't exist, then creates
a new instance and returns.
This is used when we want to limit the object creation to
only one object for a particular class. e.g., For a
company, we would like to limit the object of type CEO to
be only one. (that means, we know that only 1 CEO exists
for a company).
| Is This Answer Correct ? | 8 Yes | 0 No |
What is inheritance c#?
Distinguish between continue and break statement?
What is dynamic in c#?
What are the 3 different types of arrays?
Why is xml called extensible?
What is dynamic object in c#?
How can I create a process that is running a supplied native executable (e.g., Cmd.exe)?
What is the difference between int.parse and int.tryparse methods?
Is system a class in c#?
What is dataview c#?
What happens if the inherited interfaces have conflicting method names?
Where is the output of TextWriterTraceListener redirected?
1 Answers Rolta, Siebel Systems,
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)