adspace


How to implement singleton design pattern in c#?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

How to assign Null value to Var?

1071


Why can't we use a static class instead of singleton?

962


Which namespaces are necessary to create a localized application?

1147


What is an abstract class c#?

973


What is expression tree in c#?

1004


How do you inherit a class into other class in c#?

999