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
要移除的房產價值。
例外狀況
屬性值為空參考(Nothing 在 Visual Basic)。
在呼叫底層介面時發生錯誤。
範例
// 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 類別有兩個字串屬性代表該項目)。 移除這些項目的方法是先在集合中找到物件(透過迴圈所有物件),然後用你剛找到的物件指標呼叫 Remove 函式。 以下範例說明了這一點。