日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#之app.config、exe.config和vshost.exe.config作用区别

發布時間:2023/12/10 C# 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#之app.config、exe.config和vshost.exe.config作用区别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


vshost.exe.config是程序運行時的配置文本?
exe.config是程序運行后會復制到vshost.exe.config?
app.config是在vshost.exe.config和exe.config沒有情況起作用,從app.config復制到exe.config再復制到vshost.exe.config

寫配置文件都是寫到exe.config文件中了,app.config不會變化。?
app.config只在exe.config丟失的情況下在開發環境中重新加載app.config,vshost.exe.config和exe.config會自動創建內容跟app.config一樣。

vshost.exe.config和app.config兩個文件可不要,但exe.config文件不可少。

網絡上有很多文章是講app.config讀寫方法的,可是事實上這個文件程序就不能改變它。下面是動態修改配置文件的方法:


    public static void SaveAppSettings(string aKey, string aValue)
{
// 創建配置文件對象
string file = System.Windows.Forms.Application.ExecutablePath;

//此處修改為.vshost.exe.Config的內容
// System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(file);


if (config.AppSettings.Settings[aKey] != null)
{
// 修改
config.AppSettings.Settings[aKey].Value = aValue;
}
else
{
// 添加
AppSettingsSection ass = (AppSettingsSection)config.GetSection("appSettings");
ass.Settings.Add(aKey, aValue);
}

// 保存修改
config.Save(ConfigurationSaveMode.Modified);

// 強制重新載入配置文件的連接配置節
ConfigurationManager.RefreshSection("appSettings");
}


原文:https://www.cnblogs.com/ShaYeBlog/p/8303776.html

總結

以上是生活随笔為你收集整理的C#之app.config、exe.config和vshost.exe.config作用区别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。