8
Answers

NP48 Singleton Program

Maha

Maha

17y
2.4k
1

Hi Guys

 

Following Singleton class is given in the following website  

http://www.c-sharpcorner.com/UploadFile/faraz.rasheed/SingletonPattern12052005063955AM/SingletonPattern.aspx

 

Complete program will give better understanding. Please anyone can develop appropriate client code (Main method) for this partial Singleton class Program.  

         

Thank you

 

class Singleton

{

    private static Singleton instance;

    private static int numOfReference;

    private string code;

 

    private Singleton()

    {

        numOfReference = 0;

        code = "Maasoom Faraz";

    }

    public static Singleton GetInstance()

    {

        if (instance == null)

        {

            instance = new Singleton();

        }

        numOfReference++;

        return instance;

    }

    public static int Reference

    {

        get { return numOfReference; }

    }

    public string Code

    {

        get { return code; }

        set { code = value; }

    }

}

 

Answers (8)