Collection.Remove Collection.Remove Collection.Remove Collection.Remove Method

定义

Collection 对象移除元素。Removes an element from a Collection object.

重载

Remove(Int32) Remove(Int32) Remove(Int32) Remove(Int32)

Collection 对象移除元素。Removes an element from a Collection object.

Remove(String) Remove(String) Remove(String) Remove(String)

Collection 对象移除元素。Removes an element from a Collection object.

Remove(Int32) Remove(Int32) Remove(Int32) Remove(Int32)

Collection 对象移除元素。Removes an element from a Collection object.

public:
 void Remove(int Index);
public void Remove (int Index);
member this.Remove : int -> unit
Public Sub Remove (Index As Integer)

参数

Index
Int32 Int32 Int32 Int32

一个数值表达式,用于指定集合的元素位置。A numeric expression that specifies the position of an element of the collection. Index 必须为介于 1 到集合的 Count 属性的值之间的数字。Index must be a number from 1 through the value of the collection's Count property.

示例

此示例演示如何使用Remove方法Collection从变量birthdays中的对象中删除对象。This example illustrates the use of the Remove method to remove objects from a Collection object in the variable birthdays.

Dim birthdays As New Collection()
birthdays.Add(New DateTime(2001, 1, 12), "Bill")
birthdays.Add(New DateTime(2001, 1, 13), "Joe")
birthdays.Add(New DateTime(2001, 1, 14), "Mike")
birthdays.Add(New DateTime(2001, 1, 15), "Pete")
birthdays.Remove(1)
birthdays.Remove("Mike")

Add方法进行四次调用后Count ,属性包含4,元素"Bill"的索引值为1,元素"Pete"的索引值为4。Following the four calls to the Add method, the Count property contains 4, element "Bill" has index value 1, and element "Pete" has index value 4.

Remove一次调用后, Count的值为3,元素"Bill"将被删除"Pete" ,并且元素的索引值为3。Following the first call to Remove, Count is 3, element "Bill" is deleted, and element "Pete" has index value 3.

在第二次调用RemoveCount ,的值为"Mike" 2,元素将被"Pete"删除,并且元素的索引值为2。Following the second call to Remove, Count is 2, element "Mike" is deleted, and element "Pete" has index value 2.

注解

Remove从集合中删除某个元素时,它会将集合Count的属性减一。When Remove deletes an element from a collection, it decrements the collection's Count property by one. 它还减少Index了集合中以前跟已删除元素的每个元素的值。It also decrements the Index value of every element that formerly followed the deleted element in the collection.

如果在没有的Key情况下将某个元素添加到集合中,则必须使用它Index将其删除。If an element was added to the collection without a Key, you must use its Index to remove it.

Remove(String) Remove(String) Remove(String) Remove(String)

Collection 对象移除元素。Removes an element from a Collection object.

public:
 void Remove(System::String ^ Key);
public void Remove (string Key);
member this.Remove : string -> unit
Public Sub Remove (Key As String)

参数

Key
String String String String

指定键字符串的唯一 String 表达式,可以使用此键字符串代替位置索引访问集合中的元素。A unique String expression that specifies a key string that can be used, instead of a positional index, to access an element of the collection. Key 必须对应于将元素添加到集合中时指定的 Key 参数。Key must correspond to the Key argument specified when the element was added to the collection.

示例

此示例演示如何使用Remove方法Collection从变量birthdays中的对象中删除对象。This example illustrates the use of the Remove method to remove objects from a Collection object in the variable birthdays.

Dim birthdays As New Collection()
birthdays.Add(New DateTime(2001, 1, 12), "Bill")
birthdays.Add(New DateTime(2001, 1, 13), "Joe")
birthdays.Add(New DateTime(2001, 1, 14), "Mike")
birthdays.Add(New DateTime(2001, 1, 15), "Pete")
birthdays.Remove(1)
birthdays.Remove("Mike")

Add方法进行四次调用后Count ,属性包含4,元素"Bill"的索引值为1,元素"Pete"的索引值为4。Following the four calls to the Add method, the Count property contains 4, element "Bill" has index value 1, and element "Pete" has index value 4.

Remove一次调用后, Count的值为3,元素"Bill"将被删除"Pete" ,并且元素的索引值为3。Following the first call to Remove, Count is 3, element "Bill" is deleted, and element "Pete" has index value 3.

在第二次调用RemoveCount ,的值为"Mike" 2,元素将被"Pete"删除,并且元素的索引值为2。Following the second call to Remove, Count is 2, element "Mike" is deleted, and element "Pete" has index value 2.

注解

Remove从集合中删除某个元素时,它会将集合Count的属性减一。When Remove deletes an element from a collection, it decrements the collection's Count property by one. 它还减少Index了集合中以前跟已删除元素的每个元素的值。It also decrements the Index value of every element that formerly followed the deleted element in the collection.

如果在没有的Key情况下将某个元素添加到集合中,则必须使用它Index将其删除。If an element was added to the collection without a Key, you must use its Index to remove it.

适用于