How to implement a singleton design pattern in c#?



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

Answer / Suman Lata Verma

To create a singleton pattern in C#, you can make a class constructor private and provide a static property that returns the single instance of the class. Here's an example: `public sealed class Singleton {n private static readonly Singleton _instance = new Singleton();n private Singleton() { }n public static Singleton Instance => _instance;n}`

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

What are circular references? How garbage collection deals with circular references.

1 Answers  


Why data types are important in c#?

1 Answers  


What are the the three types of DAO ?

1 Answers  


If a class derives from another class, will the derived class automatically contain all the public, protected, and internal members of the base class?

1 Answers  


What are synchronous and asynchronous operations?

1 Answers  


How do you specify a custom attribute for the entire assembly (rather than for a class)?

1 Answers  


How to transpose rows into columns and columns into rows in a multi-dimensional array?

4 Answers   Microsoft,


Is dictionary reference type c#?

1 Answers  


Can structs in c# have destructors?

1 Answers  


What are the different types of constructors in c#?

1 Answers  


What are the various components in crystal reports?

1 Answers  


What is the use of multicast delegate while methods of multicast delegate do not execute in a order?

2 Answers  


Categories