|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Extension Indexer Property
Provides access to individual elements in a collection.
You can use the extension indexer property to access individual elements in a collection. This indexer property is typically used on the output of XML axis properties. The XML child and XML descendent axis properties return collections of XElement objects or an attribute value.
The Visual Basic compiler converts extension indexer properties to calls to theElementAtOrDefault method. Unlike an array indexer, theElementAtOrDefault method returns Nothing if the index is out of range. This behavior is useful when you cannot easily determine the number of elements in a collection.
The following example shows how to use the extension indexer to access the second child node in a collection of XElement objects. The collection is accessed by using the child axis property, which gets all child elements named phone in the contact object.
This code displays the following text:
Second phone number: 425-555-0145