以定义一个 static class, 再定义一个静态的字段或者属性就可以了,
public static class CommonData
{
private static int data = 0;
public static int Data
{
get { return data; }
set { data = value; }
}
}
可以这样引用:CommonData.Data
也可以定义一个 Singleton 的类, 公开一些字段或者属性.
public sealed class CommonData
{
private int data;
private static CommonData instance = new CommonData();
private CommonData() { }
public static CommonData Instance
{
get { return instance; }
set { instance = value; }
}
public int Data
{
get { return data; }
set { data = value; }
}
}