ConfigurationManager.AppSettings 屬性 —轉

來源:互聯網
上載者:User
ConfigurationManager.AppSettings 屬性 

注意:此屬性在 .NET Framework 2.0 版中是新增的。

命名空間:System.Configuration
程式集:System.Configuration(在 system.configuration.dll 中)

文法Visual Basic(聲明)
Public Shared ReadOnly Property AppSettings As NameValueCollection
Visual Basic(用法)
Dim value As NameValueCollectionvalue = ConfigurationManager.AppSettings
C#
public static NameValueCollection AppSettings { get; }
C++
public:static property NameValueCollection^ AppSettings {    NameValueCollection^ get ();}
J#
/** @property */public static NameValueCollection get_AppSettings ()
JScript
public static function get AppSettings () : NameValueCollection

 

 

屬性值

返回一個 NameValueCollection 對象,該對象包含當前應用程式預設配置的 AppSettingsSection 對象的內容。 異常

異常類型 條件

ConfigurationErrorsException

無法使用應用程式設定資料檢索 NameValueCollection 對象。

備忘

AppSettingsSection 對象包含設定檔的 appSettings 節的內容。

樣本

下面的程式碼範例示範如何使用 AppSettings 屬性擷取命名的應用程式設定。

Visual Basic
' Get appSettings.Shared Sub GetAppSettings()   ' Get the appSettings.     Dim appSettings As NameValueCollection = _     ConfigurationManager.AppSettings      ' Get the collection enumerator.     Dim appSettingsEnum As IEnumerator = _     appSettings.Keys.GetEnumerator()      ' Loop through the collection and   ' display the appSettings key, value pairs.   Dim i As Integer = 0   While appSettingsEnum.MoveNext()      Dim key As String = appSettings.Keys(i)         Console.WriteLine("Name: {0} Value: {1}", _         key, appSettings(key))      i += 1   End WhileEnd Sub 'GetAppSettings 
C#
// Get appSettings.static void GetAppSettings(){    // Get the appSettings.    NameValueCollection appSettings =         ConfigurationManager.AppSettings;        // Get the collection enumerator.    IEnumerator appSettingsEnum =        appSettings.Keys.GetEnumerator();    // Loop through the collection and    // display the appSettings key, value pairs.    int i = 0;    Console.WriteLine("App settings.");    while (appSettingsEnum.MoveNext())    {        string key = appSettings.Keys[i];        Console.WriteLine("Name: {0} Value: {1}",        key, appSettings[key]);        i += 1;    }}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.