In this post we will discuss about Singleton class in C#.Net. Also you can check out my previous posts on:
- Identity in sql server 2008
- Upload multiple files in Asp.Net file upload control
- Post form data to 3rd party URL in Asp.Net
Singleton class allows only one instance. This is helpful if you want only one object of a class to perform operations.
Below is a way to implement:
using System;
public class Singleton
{
private static Singleton instance;
private Singleton() {}
public static Singleton Instance
{
get
{
if (instance == null)
{
instance = new Singleton();
}
return instance;
}
}
}
- Identity in sql server 2008
- Upload multiple files in Asp.Net file upload control
- Post form data to 3rd party URL in Asp.Net
Singleton class allows only one instance. This is helpful if you want only one object of a class to perform operations.
Below is a way to implement:
using System;
public class Singleton
{
private static Singleton instance;
private Singleton() {}
public static Singleton Instance
{
get
{
if (instance == null)
{
instance = new Singleton();
}
return instance;
}
}
}