NameValueConfigurationCollection.Add(NameValueConfigurationElement) 方法

定义

NameValueConfigurationElement 对象添加到集合中。

public:
 void Add(System::Configuration::NameValueConfigurationElement ^ nameValue);
public void Add (System.Configuration.NameValueConfigurationElement nameValue);
member this.Add : System.Configuration.NameValueConfigurationElement -> unit
Public Sub Add (nameValue As NameValueConfigurationElement)

参数

示例

下面的代码示例演示如何使用 Add 方法。 此代码示例是为 NameValueConfigurationCollection 类提供的一个更大示例的一部分。

foreach (PropertyInformation propertyItem in
  configSection.ElementInformation.Properties)
{
    // Assign  domain name.
    if (propertyItem.Name == "domain")
        propertyItem.Value = "MyDomain";

    if (propertyItem.Value != null)
    {
        // Enable SSL for cookie exchange.
        if (propertyItem.Name == "cookieRequireSSL")
            propertyItem.Value = true;

        NameValueConfigurationElement nameValConfigElement =
            new NameValueConfigurationElement
                (propertyItem.Name.ToString(), propertyItem.Value.ToString());

        // Add a NameValueConfigurationElement
        // to the collection.
        myNameValConfigCollection.Add(nameValConfigElement);
    }
}
For Each propertyItem As PropertyInformation In configSection.ElementInformation.Properties
    ' Assign  domain name.
    If propertyItem.Name = "domain" Then
        propertyItem.Value = "MyDomain"
    End If

    If propertyItem.Value <> Nothing Then
        ' Enable SSL for cookie exchange.
        If propertyItem.Name = "cookieRequireSSL" Then
            propertyItem.Value = True
        End If

        Dim nameValConfigElement As New NameValueConfigurationElement(propertyItem.Name.ToString(), propertyItem.Value.ToString())

        ' Add a NameValueConfigurationElement
        ' to the collection.

        myNameValConfigCollection.Add(nameValConfigElement)
    End If
Next

注解

Add使用 方法向集合添加新NameValueConfigurationElement对象。

适用于