Returns an item by index or key from a List or Dictionary collection. This works on:

  • Array (int)
  • Array List (int)
  • IList (int)
  • ICollection (any type)
  • HashSet (any type)
  • IDictionary (key type) (or int for index)

You can specify either an integer for list types or any type for collections. int keys are 0 based.

For dictionaries int values retrieve the item at the specified indexed location, unless the Dictionary key type is int.

If the key type is int (or a FoxPro number) the int key is treated as a key value, rather than an index. For all other key types, the key is treated as an index.

public object Item(object indexOrKey)

Return Value

matching item or null


int 0 based key for lists or any value for collections/dicionaries


Invalid index or key type


Dictionaries can use an int value to return a value out of the collection by its index **if the key type is not of System.Int. This is a special case and allows you to iterate a dictionary which otherwise would not be possible.


*** Access generic list through indirect access through Proxy and get ComArray
loList = loBridge.InvokeMethod(loNet,"GetGenericList")
? loBridge.ToString(loList)   && System.Collections.Generic.List...
? loList.Count && 2

*** Grab an item by index
loCust =  loList.Item(0)
? loCust.Company

*** Iterate the list
FOR lnX = 0 TO loList.Count -1
   loItem = lolist.Item(lnX)
   ? loItem.Company
*** Retrieve a generic dictionary 
loList = loBridge.InvokeMethod(loNet,"GetDictionary")
? loList.Count  &&  2

*** Return Item by Key
loCust =  loList.Item("Item1")   && Retrieve item by Key
? loCust.Company

*** This works as long as the key type is not int
loCust =  loList.Item(0)   && Retrieve item by Index
? loCust.Company

*** This allows iterating a dictionary
FOR lnX = 0 TO loList.Count -1
   loItem = lolist.Item(lnX)
   ? loItem.Company

See also:

Class ComArray

© West Wind Technologies, 2023 • Updated: 01/13/23
Comment or report problem with topic