How to implement singleton design pattern in c#?



How to implement singleton design pattern in c#?..

Answer / Raj Kapoor Agrahari

"To implement Singleton Design Pattern in C#, create a class with a private constructor and a static property that returns the single instance of the class. Here is an example:nn```csharpnpublic sealed class Singleton{nprivate static readonly Singleton _instance = new Singleton();nnprivate Singleton() {n}npublic static Singleton Instance {nget { return _instance; }n}n}n``

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

What is the difference between array.find method and arraylist.find method?

1 Answers   Mphasis,


Why we use extension method in c#?

1 Answers  


What is an Interface in C#?

1 Answers   TryTechnicals Pvt Ltd,


What is the use of command builder?

1 Answers  


What is the difference between “finalize” and “finally” methods in c#?

1 Answers  


What is the difference between method and constructor in c#?

1 Answers  


What are the differences between events and delegates in c#?

1 Answers  


What is cshtml?

1 Answers  


Is it good to use var in c#?

1 Answers  


Define thread? Explain about multithreading?

1 Answers  


Can a static class have a constructor c#?

1 Answers  


Does c# support #define for defining global constants?

1 Answers  


Categories