Databases Reference
In-Depth Information
Operations on Collections
The properties and methods that client application code can use to operate with collec-
tions are the same for all ADOMD.NET collections, as shown in Figure 33.9.
IEnumerable
ICollection
AdomdClient.XCollection
FIGURE 33.9
All ADOMD.NET collections implement IEnumerable and ICollection inter-
faces.
Each collection in ADOMD.NET implements the IEnumerable and ICollection interfaces
and all the methods and properties supported by those interfaces described here.
Count
Count returns the number of elements in the collection.
Item
Item ( indexer in C#) provides access to the elements of a collection. ADOMD.NET
provides two overloads for this method: by index and by name. For example, in C#, access
to the elements of a collection can be expressed with this code:
Dimension dim = cube.Dimensions[0];
This call returns the first element of the collection. Or you could use the following:
Dimension dim = cube.Dimensions[“Customer”];
This call returns an element of a collection with the name Customer . Note that it uses a
name rather than a unique name.
Access to an element of a collection by index is more efficient than by name. If you have
the opportunity, use the first method. (In some of our following examples, we use access
by name, but we have done that only for the sake of simplicity.)
If no element with that name exists in the collection, or if an index oversteps the bounds
of a collection, an exception is thrown. Because exception handling always slows down
the system, use these methods only if you know that the element exists in the collection.
Find
Find returns the specified element of the collection. Unlike Item , it does not throw an
exception, but returns null if the object doesn't exist in the collection. For example
Dimension dim = cube.Dimensions.Find(“Customer”);
returns an object with the name Customer , but
Search WWH ::




Custom Search