PropertyValueCollection.Remove(Object) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从此集合中删除指定的属性值。
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 函数。 如下面的示例中所示。