PropertyValueCollection.Remove(Object) 方法

定義

從此集合移除指定的屬性值。

public:
 void Remove(System::Object ^ value);
public void Remove (object value);
public void Remove (object? value);
member this.Remove : obj -> unit
Public Sub Remove (value As Object)

參數

value
Object

要移除的屬性值。

例外狀況

屬性值為 null 參考 (在 Visual Basic 中為 Nothing)。

呼叫基礎介面期間發生錯誤。

範例

// Bind to the AD object  
DirectoryEntry myUser = new DirectoryEntry("LDAP://AdServer:389/CN=MyUsername,CN=Users,DC=contoso,DC=com");  

// Get the attribute  
PropertyValueCollection testAttribute = myUser.Properties["someAttribute"];  

// Find the item in the collection that we want to delete  
DNWithString dnwsItemToRemove = null;  
foreach (DNWithString dnwsItem in testAttribute)  
{  
    if (dnwsItem.StringValue.Equals("SomeValue"))  
    {  
        dnwsItemToRemove = dnwsItem;  
        break;  
    }  
}  

// Delete it  
testAttribute.Remove(dnwsItemToRemove);  

// Store the data  
myUser.CommitChanges();  

備註

使用多重值字串屬性值時, Remove 方法會成功移除正確的專案。 不過,使用多重值 DNWithString 屬性值 (作為 DNWithString COM 類別,以名稱識別正確的專案很困難,而 DNWithString 專案用來儲存 DNWithString 專案時,有 2 個字符串屬性代表專案) 。 拿掉這類專案的方式是在集合中尋找物件 (,方法是迴圈查看所有專案) ,然後使用您剛才找到的物件指標呼叫 Remove 函式。 如下列範例所示。

適用於