Collection.Item[String] Collection.Item[String] Collection.Item[String] Collection.Item[String] Property

定义

重载

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

按位置或键获取 Collection 对象的特定元素。Gets a specific element of a Collection object either by position or by key.

Item[Object] Item[Object] Item[Object] Item[Object]

按位置或键获取 Collection 对象的特定元素。Gets a specific element of a Collection object either by position or by key.

Item[String] Item[String] Item[String] Item[String]

按位置或键获取 Collection 对象的特定元素。Gets a specific element of a Collection object either by position or by key.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

按位置或键获取 Collection 对象的特定元素。Gets a specific element of a Collection object either by position or by key.

public:
 property System::Object ^ default[int] { System::Object ^ get(int Index); };
public object this[int Index] { get; }
member this.Item(int) : obj
Default Public ReadOnly Property Item(Index As Integer) As Object

参数

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. 或 (B) 指定集合中元素的位置或键字符串的 Object 表达式。Or (B) An Object expression that specifies the position or key string of an element of the collection.

属性值

Collection对象的特定元素(按位置或键)。A specific element of a Collection object either by position or by key.

示例

下面的示例使用Item属性来检索对集合中对象的引用。The following example uses the Item property to retrieve a reference to an object in a collection. birthdays "Bill"以对象的形式创建,然后检索表示帐单生日的对象,并Index使用键作为参数。 CollectionIt creates birthdays as a Collection object and then retrieves the object representing Bill's birthday, using the key "Bill" as the Index argument.

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")
Dim aBirthday As DateTime
aBirthday = birthdays.Item("Bill")
MsgBox(CStr(aBirthday))
aBirthday = birthdays("Bill")
MsgBox(CStr(aBirthday))

请注意,第一次调用显式Item指定了属性,但第二次调用不指定。Note that the first call explicitly specifies the Item property, but the second does not. 因为Item属性是Collection对象的默认属性,所以这两个调用都有效。Both calls work because the Item property is the default property for a Collection object.

注解

如果Index的类型Object为,则Item属性将尝试将其String视为、 CharChar数组或整数值。If Index is of type Object, the Item property attempts to treat it as a String, Char, Char array, or integer value. 如果Item无法转换IndexString ArgumentException或,Integer则会引发异常。If Item cannot convert Index to String or Integer, it throws an ArgumentException exception.

Item属性是集合的默认属性。The Item property is the default property for a collection. 因此,以下代码行是等效的。Therefore, the following lines of code are equivalent.

MsgBox(CStr(customers.Item(1)))  
MsgBox(CStr(customers(1)))  

Item[Object] Item[Object] Item[Object] Item[Object]

按位置或键获取 Collection 对象的特定元素。Gets a specific element of a Collection object either by position or by key.

public:
 property System::Object ^ default[System::Object ^] { System::Object ^ get(System::Object ^ Index); };
public object this[object Index] { get; }
member this.Item(obj) : obj
Default Public ReadOnly Property Item(Index As Object) As Object

参数

Index
Object Object Object Object

一个数值表达式,用于指定集合的元素位置。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. 或 (B) 指定集合中元素的位置或键字符串的 Object 表达式。Or (B) An Object expression that specifies the position or key string of an element of the collection.

属性值

Collection对象的特定元素(按位置或键)。A specific element of a Collection object either by position or by key.

示例

下面的示例使用Item属性来检索对集合中对象的引用。The following example uses the Item property to retrieve a reference to an object in a collection. birthdays "Bill"以对象的形式创建,然后检索表示帐单生日的对象,并Index使用键作为参数。 CollectionIt creates birthdays as a Collection object and then retrieves the object representing Bill's birthday, using the key "Bill" as the Index argument.

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")
Dim aBirthday As DateTime
aBirthday = birthdays.Item("Bill")
MsgBox(CStr(aBirthday))
aBirthday = birthdays("Bill")
MsgBox(CStr(aBirthday))

请注意,第一次调用显式Item指定了属性,但第二次调用不指定。Note that the first call explicitly specifies the Item property, but the second does not. 因为Item属性是Collection对象的默认属性,所以这两个调用都有效。Both calls work because the Item property is the default property for a Collection object.

注解

如果Index的类型Object为,则Item属性将尝试将其String视为、 CharChar数组或整数值。If Index is of type Object, the Item property attempts to treat it as a String, Char, Char array, or integer value. 如果Item无法转换IndexString ArgumentException或,Integer则会引发异常。If Item cannot convert Index to String or Integer, it throws an ArgumentException exception.

Item属性是集合的默认属性。The Item property is the default property for a collection. 因此,以下代码行是等效的。Therefore, the following lines of code are equivalent.

MsgBox(CStr(customers.Item(1)))  
MsgBox(CStr(customers(1)))  

Item[String] Item[String] Item[String] Item[String]

按位置或键获取 Collection 对象的特定元素。Gets a specific element of a Collection object either by position or by key.

public:
 property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ Key); };
public object this[string Key] { get; }
member this.Item(string) : obj
Default Public ReadOnly Property Item(Key As String) As Object

参数

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.

属性值

Collection对象的特定元素(按位置或键)。A specific element of a Collection object either by position or by key.

示例

下面的示例使用Item属性来检索对集合中对象的引用。The following example uses the Item property to retrieve a reference to an object in a collection. birthdays "Bill"以对象的形式创建,然后检索表示帐单生日的对象,并Index使用键作为参数。 CollectionIt creates birthdays as a Collection object and then retrieves the object representing Bill's birthday, using the key "Bill" as the Index argument.

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")
Dim aBirthday As DateTime
aBirthday = birthdays.Item("Bill")
MsgBox(CStr(aBirthday))
aBirthday = birthdays("Bill")
MsgBox(CStr(aBirthday))

请注意,第一次调用显式Item指定了属性,但第二次调用不指定。Note that the first call explicitly specifies the Item property, but the second does not. 因为Item属性是Collection对象的默认属性,所以这两个调用都有效。Both calls work because the Item property is the default property for a Collection object.

注解

如果Index的类型Object为,则Item属性将尝试将其String视为、 CharChar数组或整数值。If Index is of type Object, the Item property attempts to treat it as a String, Char, Char array, or integer value. 如果Item无法转换IndexString ArgumentException或,Integer则会引发异常。If Item cannot convert Index to String or Integer, it throws an ArgumentException exception.

Item属性是集合的默认属性。The Item property is the default property for a collection. 因此,以下代码行是等效的。Therefore, the following lines of code are equivalent.

MsgBox(CStr(customers.Item(1)))  
MsgBox(CStr(customers(1)))  

适用于