Why do integers need to be converted to strings before they can be used to access items in a collection?

I am new to VB in general. I am looking at some old VB code and I see statements like -

  Addr.AddrType(CStr(0)).A_Type = " "

Why does the integer 0 need to be converted to a string?

Note that Addr is defined as

 Public Addr As clsAddressDetail 

AddrType is defined as a collection.

 Public AddrType As New Collection
+3
source share
2 answers

The class used here Collectionhas what is actually an overloaded index . My emphasis:

Returns a specific element of the Collection object either by position or by key . Only for reading.

Default Public ReadOnly Property Item( _
ByVal { Key As String | Index As Integer | Index As Object } _ ) As Object

Parameters

Key

String, , . Key, , .

(A) , . 1 Count Count ( ). (B) , .

, AddrType(0), , 1 . AddrType("0"), , "0". - , , , .

, , CStr(0), "0" ...

+4

CStr() AddrType. , . , : . "0" , ; , , , , .

+1

All Articles