Chapter 11: Branching and Looping

 

Online Data Storage (Arrays)

At one time there were entire college computer science courses devoted to the study of creating new ways to make lists in a computer. There were linked lists, multiply-linked lists, circular lists, and on and on. Every time a prototype of a new type of list was announced in the mathematical and computational journals, anxious graduate students would turn out reams of proposals to study how this new list could be loaded, fetched , searched, and sorted. There were studies reported in national journals to prove which list methods were superior .

Then the database industry moved into the fray, and developed turn-key systems that would store more data than man had ever conceived of in the last thousand years . Built into these turnkey systems were algorithms that loaded, fetched, searched, and sorted data (like the huge systems that track airline reservations , for example, or the national telephone book).

Meanwhile, all that the average computer programmer wanted was a simple and convenient way to store intermediate data that his or her algorithm could process in real time to produce reasonable outputs. After 40 years of innovation, nothing has been found to serve the average computer application better than the simple array, be it one-dimensional, two-dimensional, or even three-dimensional.

Visual Studio C# made life easy to account for multiple dimensioned arrays with the invention of the jagged array. The jagged array is a group of ANSIStrings that are grouped together for ease of fetch, but each ANSIString has its own length . Recall that each ANSIString is a structure with two elements: the string text and the string length.

For the individual ANSIString there is no declared dimension. The string computes its own length and puts that number into ANSIString-Name.Length. If you have a collection of 10 strings you can provide space for them in memory by giving them all the same name , such as ANSIStringCollection[0] through ANSIStringCollection[9]. The declaration for such a collection of ANSIStrings is:

 string[] ANSIStringCollection = new string[10]; 

Remember that this is a declaration for a two-dimensional string array, and one of the dimensions is unexpressed ” only the individual string knows its length.

If you require a three-dimensional string array, the declaration is:

 string[ , ] ANSIStringWad = new string[10, 20]; 
Note  

These rules do not apply to groups of integers, floats, doubles, etc., because these groups are not jagged. Each item in the array occupies the same number of bytes in memory. For example, this declaration:

 int[ , ] intWadOfNumbers = new int[10, 20]; 

means exactly the same thing it meant in C and C++: There are 10 groups of 20 integers each (and each integer fills the same number of bytes in memory).

 


Unlocking Microsoft C# V 2.0 Programming Secrets
Unlocking Microsoft C# V 2.0 Programming Secrets (Wordware Applications Library)
ISBN: 1556220979
EAN: 2147483647
Year: 2005
Pages: 129

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