The for Loop

 

Array Initialization

To initialize a jagged array, you enter the arrays just as you always have in the past, as shown in line PL0302 below.

 PL0300:      void OnPrintPage(object obj, PrintPageEventArgs ppea) PL0301:      { // Create the 11 records at the top of the printed page. PL0302:      string[] strRT = new string[] {"KT Weekly Net Worth", "Item No", "Year-Week",                "Total Worth", "Total Cost", "Gain / Loss","----------","---------------",                "---------------","--------------","---------------"}; 

This is how you initialize integer arrays:

 PL0303:      int[] Base6 = new int[] {1270,0,800,1600,2400,3200,0,800,1600,2400,3200}; PL0304:      int[]Y6 = new int[] {160,350,350,350,350,350,460,460,460,460,460}; PL0305:      int[] Data6 = new int[] {100,910,1650,2400,3300}; 

The compiler counts the number of items in the curly brackets and sets this number as the dimension of the integer array. A string of strings (PL0302) need not be dimensioned if it is going to be initialized in the declaration ” the compiler counts the number of entries in the enumeration of the strings and sets that dimension.

To initialize a two-dimensional integer array we recommend that you proceed carefully :

 Int[ , ] TwoDArray = new[2,6] {{3,4,5,6,8,12} , {-2,16,77,4,8,8}}; 

In the case shown above, the string and integer arrays are declared locally in a procedure named OnPrintPage. If other procedures within one form need these dimensions, the declarations must be moved to the top of the FormX.cs source code file and characterized as private. If the numbers are required in other windows , they must be characterized as public and each window that needs the numbers must be sent a handle to reach the numbers (see Chapter 5).

 


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