環境 vs2010
讀取很簡單基本都用過 ConfigurationManager.AppSettings[""].ToString()
寫config不是很常用。代碼如下:
if (config.AppSettings.Settings[key] != null)
config.AppSettings.Settings[key].Value = value;
else
config.AppSettings.Settings.Add(key, value);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
原因:
在我們調試的時候(按F5) 編譯器會把debug下的exe,dll,config給覆蓋掉。然后執行exe文件和vshost.exe(此文件調試的時候用)。這時會把debug下的config內容改變。
而項目下的app.config文件并沒有改變。。。所以下回調試的時候debug下的config又被app.config覆蓋。。所以就看到了我上面所說的情況。。
新聞熱點
疑難解答