c#中单例的实现

来源:互联网 发布:c语言制表符是什么 编辑:程序博客网 时间:2024/06/16 21:48
#region "实现这个窗口类的单例,单例类常用于被主窗口以show()方法打开的窗口,使用单例后只会打开一个此类的对象"        //1.私有化构造函数,使在外部不能new(开辟堆空间,创建对象,调用构造函数)        private FStudentMan()        {            InitializeComponent();        }        //2.创建一个静态的私有的窗体类的变量         private static FStudentMan single;        //3.创建一个静态的公共的方法返回窗体类对象        public static FStudentMan GetSingle()        {            if (single == null||single.IsDisposed)            {                single=new FStudentMan();            }            return single;        }#endregion

0 0
原创粉丝点击