แก้ไข

แชร์ผ่าน


PropertyValueCollection.Remove(Object) Method

Definition

Removes a specified property value from this collection.

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)

Parameters

value
Object

The property value to remove.

Exceptions

The property value is a null reference (Nothing in Visual Basic).

An error occurred during the call to the underlying interface.

Examples

// 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();  

Remarks

When working with a multi-valued string property value, the Remove method will successfully remove the correct item. However, identifying the correct items by name is difficult with a multi-valued DNWithString property value (as the DNWithString COM class, which is used to store the DNWithString items, has 2 string properties representing the item). The way to remove such items is to find the object in the collection (by looping thru all the items), then call the Remove function with the object's pointer that you just found. This is illustrated in the example below.

Applies to