扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
The purpose of the Singleton pattern is to ensure that there is only one instance of a class, and that there is a global access point to that object.
创新互联-专业网站定制、快速模板网站建设、高性价比肥乡网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式肥乡网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖肥乡地区。费用合理售后完善,10余年实体公司更值得信赖。Design:
Implementation:
public sealed class Singleton
{
// Private constructor. private Singleton()
{
Console.WriteLine("One instance is created.");
}
// private object instantiated with private constructor. private static readonly Singleton instance = new Singleton();
// Public static property to get the object. public static Singleton UniqueInstance
{
get
{
return instance;
}
}
}
class Program
{
static void Main(string[] args)
{
Singleton s0= Singleton.UniqueInstance;
Singleton s1= Singleton.UniqueInstance;
Singleton s2= Singleton.UniqueInstance;
}
}
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流