Chapter 9: Conversions between Data Types

 

Integer, Double, and Decimal Enumerations

A collection of integers, doubles, or decimals is declared as an integer, double, or decimal array in this manner (recall that every one of these declarations could be prefaced with either public or private, and perhaps the const declaration):

 int[] intBunchOfIntegers = new int[4];            // Four integers. 

or

 double[] dblBunchOfDoubles = new double[6];      // Six doubles. 

or

 decimal[] decBunchOfDecimals = new decimal[9];   // Nine decimals. 

To fill these arrays you add the enumerations at the end of the declaration:

 int[] intBunchOfIntegers = new int[] {17, 3, 9, 88}; double[] dblBunchOfDoubles = new double[] {3.4, 3.1, 8.2, 6.6, 7.3, 0.8}; decimal[] decBunchOfDecimals = new decimal[] {1.1m, 2.2m, 3.3m, 4.4m, 5.5m, 5.6m,            6.m, 7.m, 3.3m}; 

Note that the number of ints, doubles, or decimals need not be dimensioned if the enumerations are included because the compiler counts the number of entries and fills in the proper dimension.

 


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