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的關係,看起來像是內存泄漏。 –