ConfigurationSectionCollection.Keys 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取此 ConfigurationSectionCollection 对象中包含的所有 ConfigurationSection 对象的键。
public:
 virtual property System::Collections::Specialized::NameObjectCollectionBase::KeysCollection ^ Keys { System::Collections::Specialized::NameObjectCollectionBase::KeysCollection ^ get(); };public override System.Collections.Specialized.NameObjectCollectionBase.KeysCollection Keys { get; }member this.Keys : System.Collections.Specialized.NameObjectCollectionBase.KeysCollectionPublic Overrides ReadOnly Property Keys As NameObjectCollectionBase.KeysCollection属性值
一个 NameObjectCollectionBase.KeysCollection 对象,包含此集合中所有节的键。
示例
下面的示例演示如何使用 Keys 属性。
static void GetKeys()
{
    try
    {
        System.Configuration.Configuration config =
        ConfigurationManager.OpenExeConfiguration(
        ConfigurationUserLevel.None);
        ConfigurationSectionCollection sections =
            config.Sections;
        foreach (string key in sections.Keys)
        {
            Console.WriteLine(
             "Key value: {0}", key);
        }
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub GetKeys()
    Try
        Dim config _
        As System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _
        ConfigurationUserLevel.None)
        Dim sections _
        As ConfigurationSectionCollection = _
        config.Sections
        Dim key As String
        For Each key In sections.Keys
            Console.WriteLine("Key value: {0}", key)
        Next key
    Catch err As ConfigurationErrorsException
        Console.WriteLine(err.ToString())
    End Try
End Sub