110,545
社区成员
发帖
与我相关
我的任务
分享
//我想定义一个这样的Config类, 用来在系统启动时从数据库中读入系统配置
public class Config
{}
public class Test
{
private xxx()
{
string name=Config["name"]; //想实现这样的代码调用. 而不是name=Config.Get("name");
//因为Config里面内容在启动时一次性从数据库读入了,很多地方应用到.
//如果每次使用都要new出来一个新实例的话势必造成不必要的开销.
}
}
public string GetValue(string key)
public void SetValue(string key,string value)
public class MyConfig
{
private List<int> configs = new List<int>();
private static readonly MyConfig instance = new MyConfig();
private MyConfig() { }
static MyConfig() { }
public static MyConfig Instance { get { return instance; } }
public int this[int idx]
{
get
{
return configs[idx];
}
set
{
configs[idx] = value;
}
}
}
int p = MyConfig.Instance[10];
public string this[string key]
{
get
{
//return ...
}
set
{
//...;
}
}
public string this[string key]
public string Config[string key]
public static string this[string key]
public static Config[string key]