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 |
If you want to convert a base type to a derived type, what type of conversion do you use?
What?s the advantage of using System.Text.StringBuilder over System.String?
Define clr in .net?
Why do we use namespace in c#?
Can a constructor be private in c#?
what is meant inheritance. can you exaplain what kind inhertance ussed in your project
How can you write a class to restrict that only one object of this class can be created (Singleton class)?
How can I create image pieces/sub image?
What does mean before a string in c#?
What is the difference between Java and .NET garbage collectors?
What are iterators?
Is c# an open source language?