I am giving a example that calls method of class that class has private constructor.
1. Create a class that has private constructor
using System;
namespace SingletonExample
{
public class User
{
private static User user = null;
private static readonly object padlock = new object();
private User()
{
}
public static User GetInstance()
{
lock (padlock)
{
if (user == null)
{
user = new User();
}
return user;
}
}
public void GetMessage()
{
Console.WriteLine("I am method of class user");
}
}
}
2. call the method in execution program
using System;
namespace SingletonExample
{
class Program
{
static void Main(string[] args)
{
User user = User.GetInstance();
user.GetMessage();
Console.ReadKey();
}
}
}
If you want to know more then read this
http://csharpindepth.com/articles/general/singleton.aspx[
^]