O'Reilly logo

Learning C# by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

System.Array

C# implements arrays with the class System.Array. The Array class has a number of useful methods. Table 15-1 shows a few of the more important methods and properties of the System.Array class.

Table 15-1. Useful methods and properties of System.Array

Method or Property

Description

Clear()

Public static method that sets a range of elements in the array to zero or to a null reference

Copy()

Overloaded public static method that copies a section of one array to another array

IndexOf()

Overloaded public static method that returns the index (offset) of the first instance of a value in a one-dimensional array

LastIndexOf()

Overloaded public static method that returns the index of the last instance of a value in a one-dimensional array

Reverse()

Overloaded public static method that reverses the order of the elements in a one-dimensional array

Sort()

Overloaded public static method that sorts the values in a one-dimensional array

IsFixedSize

Public property that returns a value indicating whether the array has a fixed size

Length

Public property that returns the length of the array

Rank

Public property that returns the number of dimensions of the array

The Array class’s static methods, Reverse() and Sort(), make manipulation of the objects within the array very easy. Note, however, that to reverse or sort the elements of the array, they must be of a type that implements the IComparable interface. (Chapter 16 describes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required