ConfigurationManager.AppSettings 属性
注意:此属性在 .NET Framework 2.0 版中是新增的。
命名空间:System.Configuration
程序集:System.Configuration(在 system.configuration.dll 中)
<script type="text/Javascript">
</script>
语法

Visual Basic(声明)
Public Shared ReadOnly Property AppSettings As NameValueCollection
Visual Basic(用法)
Dim value As NameValueCollection value = 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 对象的内容。
<script type="text/Javascript">
</script>
示例

下面的代码示例演示如何使用 AppSettings 属性获取命名的应用程序设置。
' 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 While End Sub 'GetAppSettings
// 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; } }