单例模式

在要实现单例模式的类当中添加如下代码:

实例化的时候:frmCardAppend fca=frmCardAppend .Instance;

示例:

 1 public  class frmCardAppend : Form
2 {
3 #region 私有字段
4 private static frmCardAppend _Instance = null;
5
6 #endregion
7
8
9 public frmCardAppend()
10 {
11 InitializeComponent();
12 }
13
14
15 #region 公有属性
16 public static frmCardAppend Instance
17 {
18 get
19 {
20 //第一次使用,如果没有实例,创建一个
21 if (_Instance == null)
22 {
23 _Instance = new frmCardAppend();
24 }
25
26 return _Instance;
27 }
28 }
29 #endregion
原文地址:https://www.cnblogs.com/lyhabc/p/2178682.html