您不需要将密钥数组放入
AppSettings
应用程序设置
应该是这样的:
<appSettings>
<add key="CONST1" value="Hi, I'm the first constant." />
<add key="CONST2" value="I'm the second." />
<add key="CONST3" value="And I'm the third." />
</appSettings>
在此之后,您可以创建全局静态字典,您可以从程序的所有部分访问该字典:
public static Dictionary<string, List<double>> Dataset
{
get
{
var ret = new Dictionary<string, List<double>>();
// Iterate through each key of AppSettings
foreach (string key in ConfigurationManager.AppSettings.AllKeys)
ret.Add(key, Foo(ConfigurationManager.AppSettings[key]));
eturn ret;
}
}
像
Foo method
static
属性,则需要将Foo方法定义为静态方法。因此,您的Foo方法应该如下所示:
private static List<double> Foo(string key)
{
// Process and return value
return Enumerable.Empty<double>().ToList(); // returning empty collection for demo
}
dictionary
public void ProcessData1()
{
List<double> data = Dataset["CONST1"];
//...
}