我已經定義:加載數據,並連接到屬性
public static string Firstname { get; set; }
public static string Surname { get; set; }
public static bool DocBook5 { get; set; }
public static string Language { get; set; }
我存儲在App.config該信息。
然後我用的是裝載並連接:
Firstname = ConfigurationManager.AppSettings["firstname"];
Surname = ConfigurationManager.AppSettings["surname"];
DocBook5 = Convert.ToBoolean(ConfigurationManager.AppSettings["docbook5"]);
Language = ConfigurationManager.AppSettings["language"];
但是,如果我只是給出一些屬性內容爲Console.WriteLine,它看起來像屬性爲空。 GetConfig類的完整代碼可以顯示there
也許有人知道爲什麼?
您可以分享您的app.config嗎?你的項目是一個控制檯應用程序或網絡? –
也可以告訴我爲什麼你需要靜態屬性? –
您的密鑰位於下的節點不在AppSetting下。並且您的代碼正在從appsetting部分讀取。所以你得到空白結果 –