- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Singleton Class in C#
Singleton Class allow for single allocations and instances of data. It has normal methods and you can call it using an instance.
To prevent multiple instances of the class, the private constructor is used.
Let us see an example −
public class Singleton { static Singleton b = null; private Singleton() { } }
The following is another example displaying how to display Singleton class −
Example
using System; class Singleton { public static readonly Singleton _obj = new Singleton(); public void Display() { Console.WriteLine(true); } Singleton() {} } class Demo { public static void Main() { Singleton._obj.Display(); } }
Output
True
Advertisements
To Continue Learning Please Login
Login with Google