AppSettingsSection.Settings プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
アプリケーション設定を含むキーと値のペアのコレクションを取得します。
public:
property System::Configuration::KeyValueConfigurationCollection ^ Settings { System::Configuration::KeyValueConfigurationCollection ^ get(); };
[System.Configuration.ConfigurationProperty("", IsDefaultCollection=true)]
public System.Configuration.KeyValueConfigurationCollection Settings { get; }
public System.Configuration.KeyValueConfigurationCollection Settings { get; }
[<System.Configuration.ConfigurationProperty("", IsDefaultCollection=true)>]
member this.Settings : System.Configuration.KeyValueConfigurationCollection
member this.Settings : System.Configuration.KeyValueConfigurationCollection
Public ReadOnly Property Settings As KeyValueConfigurationCollection
プロパティ値
構成ファイルのアプリケーション設定を含むキーと値のペアのコレクション。
- 属性
例
次の例では、 プロパティを Settings 使用して値を appSettings
読み取ります。
// This function shows how to read the key/value
// pairs (settings collection)contained in the
// appSettings section.
static void ReadAppSettings()
{
try
{
// Get the configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Get the appSettings section.
System.Configuration.AppSettingsSection appSettings =
(System.Configuration.AppSettingsSection)config.GetSection("appSettings");
// Get the auxiliary file name.
Console.WriteLine("Auxiliary file: {0}", config.AppSettings.File);
// Get the settings collection (key/value pairs).
if (appSettings.Settings.Count != 0)
{
foreach (string key in appSettings.Settings.AllKeys)
{
string value = appSettings.Settings[key].Value;
Console.WriteLine("Key: {0} Value: {1}", key, value);
}
}
else
{
Console.WriteLine("The appSettings section is empty. Write first.");
}
}
catch (Exception e)
{
Console.WriteLine("Exception raised: {0}",
e.Message);
}
}
' This function shows how to read the key/value
' pairs (settings collection)contained in the
' appSettings section.
Private Shared Sub ReadAppSettings()
Try
' Get the configuration file.
Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
' Get the appSettings section.
Dim appSettings As System.Configuration.AppSettingsSection = CType(config.GetSection("appSettings"), System.Configuration.AppSettingsSection)
' Get the auxiliary file name.
Console.WriteLine("Auxiliary file: {0}", config.AppSettings.File)
' Get the settings collection (key/value pairs).
If appSettings.Settings.Count <> 0 Then
For Each key As String In appSettings.Settings.AllKeys
Dim value As String = appSettings.Settings(key).Value
Console.WriteLine("Key: {0} Value: {1}", key, value)
Next key
Else
Console.WriteLine("The appSettings section is empty. Write first.")
End If
Catch e As Exception
Console.WriteLine("Exception raised: {0}", e.Message)
End Try
End Sub
' This function shows how to read the key/value
' pairs (settings collection)contained in the
' appSettings section.
Private Shared Sub ReadAppSettings()
Try
' Get the configuration file.
Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
' Get the appSettings section.
Dim appSettings As System.Configuration.AppSettingsSection = CType(config.GetSection("appSettings"), System.Configuration.AppSettingsSection)
' Get the auxiliary file name.
Console.WriteLine("Auxiliary file: {0}", config.AppSettings.File)
' Get the settings collection (key/value pairs).
If appSettings.Settings.Count <> 0 Then
For Each key As String In appSettings.Settings.AllKeys
Dim value As String = appSettings.Settings(key).Value
Console.WriteLine("Key: {0} Value: {1}", key, value)
Next key
Else
Console.WriteLine("The appSettings section is empty. Write first.")
End If
Catch e As Exception
Console.WriteLine("Exception raised: {0}", e.Message)
End Try
End Sub
適用対象
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET