1.appSettings结点
- // 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;
- }
2.connectionStrings结点
- // Get connectionStrings.
- static void GetConnectionStrings()
- {
- // Get the connectionStrings.
- ConnectionStringSettingsCollection connectionStrings =
- ConfigurationManager.ConnectionStrings;
- // Get the collection enumerator.
- IEnumerator connectionStringsEnum =
- connectionStrings.GetEnumerator();
- // Loop through the collection and
- // display the connectionStrings key, value pairs.
- int i = 0;
- Console.WriteLine("Connection strings.");
- while (connectionStringsEnum.MoveNext())
- {
- string name = connectionStrings[i].Name;
- Console.WriteLine("Name: {0 Value: {1",
- name, connectionStrings[name]);
- i += 1;
- }