规范实例是指一种经常使用的特殊实例,因此保持总是可用的状态是很有意义的。就像system.string这个类就有实现一个这样的规范实例--string.Empty.
实现方式:static constructor
code:
public class classA
{
private static classA commonInstance;
public static classA CommonInstanc
{get;set;}
public classA(int aa,int b,int c,int d,int e,string s,string s1,string s2,string s3,string s4)
{
a = aa;
a1 = b;
a2 = c;
//.init the property
// .
//.
//.
}
static classA()
{
//intance the commonInstance
commonInstance = new classA( 1,2,3,4,5,"4","","4","4","") ;
}
private int a;
public int A { get; set; }
private int a1;
public int A1 { get; set; }
private int a2;
public int A2 { get; set; }
private int a3;
public int A3 { get; set; }
private int a4;
public int A4 { get; set; }
private string b;
public string B { get; set; }
private string b1;
public string B1 { get; set; }
private string b2;
public string B2 { get; set; }
private string b3;
public string B3 { get; set; }
private string b4;
public string B4 { get; set; }
}
classA. commonInstance就相当于string.Empty这个被经常用到的实例了。
比如我们要创建一个类“班级”,而你的系统又是为你自己班级开发的,你自己这个班级这个实例肯定被经常用到,所以,在你的系统里可以将这个规范实例设置为你自己班级的实例。这样在你系统里就只需要填充一次你班级的实例了。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-539622/ ,如需转载,请注明出处,否则将追究法律责任。