Tuesday, January 25, 2011

Working with Singleton class

I have heard about singleton class but never use them. Reason may be we were not in need to do so. Here is the simple way to create a singleton class in C#.Net and use it.

Make a class with name Fewlines4Biju

Declare at class level
private static Fewlines4Biju fewlines4Biju;

Then make a method like:
 public static Fewlines4Biju  GetInstance()
        {
            if (fewlines4Biju == null)
            {
                fewlines4Biju = new Fewlines4Biju();
            }
            return fewlines4Biju;
        }

Fewlines4Biju fewlines4Biju = Fewlines4Biju.GetInstance();

 There are different methods available but I am trying this and it works fine for me. Hope this will work fine for you too.

No comments:

Post a Comment