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 the system namespace?
Explain publishers and subscribers in events.
I want to print "Hello" even before main() is executed. How will you achieve that?
What is overloading in c#?
What is a derived class in c#?
Can you override private virtual methods?
what is IDisposal interface,IComparable,IEquatable,IFormatable
Can we inherit singleton class in c#?
Between windows authentication and sql server authentication, which one is trusted and which one is untrusted?
Is std :: string null terminated?
Does c# support templates?
What are lambda expressions used for?
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)