ComArray.Item

Returns an item by index or by key from an Array, List or Dictionary collection.

This works on (keytype):

  • 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)

matching item or null

Parameters

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

**System.ArgumentException** <br /> Invalid index or key type

Remarks

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.

Example

*** 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
ENDFOR
*** 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
ENDFOR

See also