[Previous] [Contents] [Next]

Arrays

So far, most of the examples in this book have shown how to define variables in finite, predetermined numbers. However, in most practical applications, you don't know the exact number of objects you need until run time. For example, if you're developing an editor and you want to keep track of the controls that are added to a dialog box, the exact number of controls the editor will display can't be known until run time. You can, however, use an array to store and keep track of a dynamically allocated grouping of objects-the controls on the editor, in this case.

In C#, arrays are objects that have the System.Array class defined as their base class. Therefore, although the syntax of defining an array looks similar to that in C++ or Java, you're actually instantiating a .NET class, which means that every declared array has all the same members inherited from System.Array. In this section, I'll cover how to declare and instantiate arrays, how to work with the different array types, and how to iterate through the elements of an array. I'll also look at some of the more commonly used properties and methods of the System.Array class.

[Previous] [Contents] [Next]