public class Settings
{
public static readonly string fileName = "config.ini";
private IConfigSource src
{
get
{
CreateIfNotExists();
return new IniConfigSource(fileName);
}
}
public void test1()
{
//var src = new IniConfigSource(fileName); ;
src.Configs["DATA"].Set("baa", "haaaaee");
src.Save();
}
public void test2()
{
var src2 = new IniConfigSource(fileName); ;
src2.Configs["DATA"].Set("baa", "haaaaee");
src2.Save();
}
public Stream CreateIfNotExists()
{
if (!File.Exists(fileName))
{
Stream file = File.Create(fileName);
return file;
}
return null;
}
}
为什么test2()
方法正常工作并且test1()
无法正常工作?获得{}不能按预期工作
为什么您在test1中注释了'src'声明? – norlando
会发生什么?有抛出异常吗? –
我们需要更多的代码才能理解。 src的来源以及它与CreateIfNotExists的关系,看起来像是内存泄漏。 –