刚刚 回复一个类似的,代码 public class A { //提供唯一访问点,单一模式。 public static readonly A call = new A(); //用字典 保存数据 private static Dictionary<string, string> dicCache = new Dictionary<string, string>();
// 操作字典 public void Add(){...} public void Remove(){...} ...... } //调用 都通过 call 来操作 A.call.Add(); A.call.Remove();.....
{
private string str;
public Test(string str)
{
this.str=str;
}
method()
{
//有其他方法要用到时赋值
}
}
实例化对象时确定要调用一个方法.这个方法称为构造方法.
我们必须要么自己在类定义中定义一个,要么让CLR替我们提供
一个.
构造方法的工作是创建某个类所指定的对象,并将它置于有
效状态.
在构造方法运行前,对象只是无法区分的内存,在构造方法完成后,内存就存放了某个类型的一个有效实例.
定义结构方法时需要声明一个与类同名的方法.
{
//提供唯一访问点,单一模式。
public static readonly A call = new A();
//用字典 保存数据
private static Dictionary<string, string> dicCache = new Dictionary<string, string>();
// 操作字典
public void Add(){...}
public void Remove(){...}
......
}
//调用 都通过 call 来操作
A.call.Add();
A.call.Remove();.....