Configurationmanager. deleettings attributes
Note: This attribute is added in. NET Framework 2.0.
Namespace:System. Configuration
Assembly:System. configuration (in system. configuration. dll)
Syntax Visual Basic (Declaration)
Public Shared ReadOnly Property AppSettings As NameValueCollection
Visual Basic (usage)
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
Attribute Value
Returns a namevaluecollection object that contains the default configuration of the current application.AppsettingssectionObject content. Exception
| Exception type |
Condition |
Configurationerrorsexception |
Data Retrieval cannot be set using the applicationNamevaluecollectionObject. |
Remarks
AppsettingssectionObjects that contain the configuration fileAppsettingsSection.
Example
The following code example demonstrates how to useAppsettingsProperty to get the application settings named.
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; }}