Since both arrays in the previous example have a rank of 1, and Dog and Cat are
type-convertible to Animal, the assignment works.
nNote The full type information of an array comprises its rank (how many dimensions it has) and the type
that it contains.
Array Covariance
An array element whose type is B may actually be of type A, provided that both A and B are reference
types and that B is a base type of A or is implemented by A. This relationship is known
as array covariance. Due to this covariance, all element assignments of reference type arrays
are subject to a runtime type check to ensure that the value being assigned is an allowed type.
CHAPTER 10 n ARRAYS AND COLLECTIONS 199
Sortability and Searchability
The System.Array interface includes several methods that deal with sorting the elements
within an array. These methods are usable when the contained type implements IComparable,
the standard interface through which items of a particular type are compared. You cannot sort
a multidimensional array, as doing so will throw an exception of type RankException. Also, if
you attempt to sort an array where one or more of the members do not support IComparable,
you can expect to see an exception of type InvalidOperationException.
Using the shared methods Index() and LastIndexOf(), you can locate a specific value
within an array.
Pages:
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333