Chapter 9. Arrays and Collections


Arrays are types that enable you to store a series of elements. Every array can be thought of as being two parts in one. The first part is the array object, which is an instance of the class System.Array . This object stores information about the array itself ”things like the number of elements in the array, the number of dimensions, and whether the array has a non-zero lower bound or not. The second part is the storage for the elements in the array.

There are two main types of arrays: arrays of valuetypes and arrays of reference types. Valuetypes include the language's native data types, such as integers, longs, doubles, etc. Valuetypes also include structures. Reference types include classes that produce objects, like System.Object , Strings and any custom class you write.

If the array is an array of Valuetypes, the array object will also contain storage for each element in the array. For example, if an array is an array of ten integers, then creating the array object allocates enough memory to store all ten integers. As soon as the array is allocated you can start assigning values to each slot in the array.

On the other hand, if the array is an array of reference types, then creating the array object only allocates place holders for each element in it, and doesn't create each object in the array. For example, if you have an array of Checking accounts, creating the array only produces the memory required to store pointers to Checking objects. After the array is created you have to go through each entry and create Checking objects yourself before you can start manipulating each element in the array.

Whether the array is an array of reference types or of valuetypes, all arrays have a set of functions that enable you to manipulate and search through the array. In this chapter you'll learn how to create arrays and manipulate the arrays.

Aside from arrays, the .NET foundation classes offer a set of classes for storing elements that have more functionality than arrays. Those classes are normally referred to as collection classes because they are all part of a namespace called System.Collection . These classes include things like dynamic arrays, HashTables, queues, and others.



C#
C# & VB.NET Conversion Pocket Reference
ISBN: 0596003196
EAN: 2147483647
Year: 2003
Pages: 198
Authors: Jose Mojica

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net