Uses a jagged array to store sales figures : Array Dimension « Collections Data Structure « C# / C Sharp






Uses a jagged array to store sales figures

Uses a jagged array to store sales figures
 
/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
// Sales.cs -- Uses a jagged array to store sales figures, then writes report
//             for one month. Demonstrates that you do not have to worry about
//             looking for empty elements.
//
//             Compile this program with the following command line:
//                 C:>csc Sales.cs
//
namespace nsSales
{
    using System;
    
    public class Sales
    {
        static public void Main ()
        {
             DateTime now = DateTime.Now;
             Random rand = new Random ((int) now.Millisecond);
             int [] MonthLen = new int []
                           {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
             double [][] Sales2000 = new double [12][];
             for (int x = 0; x < MonthLen.Length; ++x)
             {
                 Sales2000[x] = new double [MonthLen[x]];
                 for (int y = 0; y < Sales2000[x].Length; ++y)
                 {
                     Sales2000[x][y] = rand.NextDouble() * 100;// % 11 + 20;
                 }
             }
             Console.Write ("February Sales Report (in thousands):");
             for (int x = 0; x < Sales2000[1].Length; ++x)
             {
                  if ((x % 4) == 0)
                      Console.WriteLine ();
                  Console.Write ("    Feb. {0,-2:D}: {1,-4:F1}", x + 1, Sales2000[1][x]);
             }
        }
    }
}



           
         
  








Related examples in the same category

1.Demonstrate a two-dimensional arrayDemonstrate a two-dimensional array
2.Sum the values on a diagonal of a 3x3x3 matrixSum the values on a diagonal of a 3x3x3 matrix
3.Initialize a two-dimensional arrayInitialize a two-dimensional array
4.Demonstrate jagged arraysDemonstrate jagged arrays
5.Use the Length array property on a 3-D arrayUse the Length array property on a 3-D array
6.Call GetLength for two dimenional array
7.Demonstrate Length with jagged arraysDemonstrate Length with jagged arrays
8.illustrates the use of a two-dimensional rectangular arrayillustrates the use of a two-dimensional rectangular array
9.initialize a two-dimensional rectangular array, and use the array properties and methodsinitialize a two-dimensional rectangular array, and use the array properties and methods
10.the use of a three-dimensional rectangular arraythe use of a three-dimensional rectangular array
11.the use of a jagged arraythe use of a jagged array
12.Uses a two-dimensional array to store grades for studentsUses a two-dimensional array to store grades for students
13.Multidimensional and Jagged Arrays:Jagged ArraysMultidimensional and Jagged Arrays:Jagged Arrays
14.Multi dimensional Arrays 1Multi dimensional Arrays 1
15.Catch OutOfMemoryException
16.Catch IndexOutOfRangeException Exception
17.Defines a 2D Array