
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- How to write a singleton class in C++?
- Why singleton class is always sealed in C#?
- What is a singleton class in Java?
- How to use singleton class in android?
- What is the difference between Static class and Singleton instance in C#?
- How we can create singleton class in Python?
- How to make a class singleton in Java?\n
- How to refresh Singleton class every one hour in android?
- How to prevent Cloning to break a Singleton Class Pattern?
- How to prevent Reflection to break a Singleton Class Pattern?
- How to prevent Serialization to break a Singleton Class Pattern?
- How to prevent Cloning to break a Singleton Class Pattern in Java?
- Explain C++ Singleton design pattern.
- Private Constructors and Singleton Classes in C#
- How to implement a Singleton design pattern in C#?

Advertisements