Language: Arrays

This sample demonstrates features of arrays. 

Featured Highlights

The application shows how to work with an array of value types, strings, and an array of reference types, a custom Customer object. The Customer object exposes public Id and Name fields. There are six command buttons which execute various procedures.

Note that in order to keep the code isolated, each array is built at the procedure level each time you click one of the buttons.

Requirements

Requires the Trial or Release version of Visual Studio .NET Professional (or greater).

Running the Sample

Changing the Array of option from Strings to Objects will enable Field to use for Sorts which controls whether an array of Customer objects is sorted by the Customer's Name field or Id field. In order for sorting or searching of an arry of objects to work, the object needs to implement the IComparable interface. This interface exposes a single method CompareTo. CompareTo simply evaluates the passed in object reference to itself using any criteria that makes since to the object. If the object passed in equals the current object, the 0 is returned. If the object is less than the current object, return 1, otherwise -1. The Customer object uses its name field as the test value to determine object equivalence. Optionally, the shared method SetCompareKey can be called before a sort is performed to change the field used.

Note that strings and primative types like integers are automatically comparable.

Last Update: 12 July 2002