Having said that you can still access the collection members in the following ways:
Using the Get accessor method
Collections are implemented using two special accessor methods called get_Item and set_Item. These special methods are generated by the .NET compiler for every publicly exposed property. In case of FindResults instance, even though the Items read-only property is not exposed in the interoperable assembly, get_Item method is still implemented internally. The only differences from the conventional .NET get_Item method are that this method takes the index value as an object passed by reference (for COM marshalling purposes) and the index starts from 1 instead of 0.
The following code shows how to use the get_Item accessor method to iterate through the list of Location objects in the FindResults collection:
//Create an object to hold index value
object index = null;
//Start with index 1 instead of 0
for(int i=1; i<=findResults.Count; i++) { //Box the integer value as an object index = i; //Pass the index as a reference to the get_Item accessor method MapPoint.Location loc = findResults.get_Item(ref index) as MapPoint.Location; if(loc != null) //do something intersting }
Using an enumerator
You can also access the list of Locations from FindResults instance using the enumeration. The FindResults instance exposes a method, GetEnumerator, to get an enumerated list of locations. Using this enumerator instance, you can loop through the list of locations as shown below:
//Get an enumerator using the GetEnumerator method
IEnumerator locationEnumerator = findResults.GetEnumerator();
//Loop through the location instances to get the names
while(locationEnumerator.MoveNext())
{
MapPoint.Location loc = locationEnumerator.Current as MapPoint.Location;
//do something interesting
}
To learn more about this topic and other related topics, please buy
Programming MapPoint in .NET
0 comments
Post a Comment