开发者

clear singleton pattern concept please

I w开发者_如何学编程ant to make connection with sql server DB and maintain in singleton pattern. So is this functionality inbuilt in dot net ? or we mannually have to write the code for this scenario?


A lazy loaded singleton example

public sealed class Singleton

{ Singleton() { }

public static Singleton Instance
{
    get
    {
        return Nested.instance;
    }
}

class Nested
{
    // Explicit static constructor to tell C# compiler
    // not to mark type as beforefieldinit
    static Nested()
    {
    }

    internal static readonly Singleton instance = new Singleton();
}

}


Make use of sqlHelper class will do work for you which is related to database connections


See here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜