Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

how to implement singelton in C# & its uses?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between a method and a property?

1033


What are the benefits of using generics?

991


What is a method signature?

994


Can a struct inherit from an interface in c#?

1016


Which is faster iqueryable or ienumerable?

989


What you mean by delegate in c#?

896


Can a dictionary have the same key?

973


What is remote data?

833


Is the following code legal?

969


What is console readkey in vb net?

1080


Explain About DTS package

966


What's the difference between WindowsDefaultLocation and WindowsDefaultBounds?

1178


Which program construct must return a value?

1075


Explain about generics in c#.net?

1049


Can abstract class have private constructor c#?

949