環(huán)境 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");
}
原因:
在我們調(diào)試的時(shí)候(按F5) 編譯器會(huì)把debug下的exe,dll,config給覆蓋掉。然后執(zhí)行exe文件和vshost.exe(此文件調(diào)試的時(shí)候用)。這時(shí)會(huì)把debug下的config內(nèi)容改變。
而項(xiàng)目下的app.config文件并沒有改變。。。所以下回調(diào)試的時(shí)候debug下的config又被app.config覆蓋。。所以就看到了我上面所說的情況。。
新聞熱點(diǎn)
疑難解答
圖片精選