Demonstrate Length with jagged arrays : Array Dimension « Collections Data Structure « C# / C Sharp






Demonstrate Length with jagged arrays

Demonstrate Length with jagged arrays
 
// Demonstrate Length with jagged arrays. 
 
using System; 
 
public class Jagged {  
  public static void Main() {  
    int[][] network_nodes = new int[4][];  
    network_nodes[0] = new int[3];  
    network_nodes[1] = new int[7];  
    network_nodes[2] = new int[2];  
    network_nodes[3] = new int[5];  
 
  
    int i, j; 
 
    // fabricate some fake CPU usage data    
    for(i=0; i < network_nodes.Length; i++)   
      for(j=0; j < network_nodes[i].Length; j++)  
        network_nodes[i][j] = i * j + 70;  
 
 
    Console.WriteLine("Total number of network nodes: " + network_nodes.Length + "\n"); 
 
    for(i=0; i < network_nodes.Length; i++) {  
      for(j=0; j < network_nodes[i].Length; j++) { 
        Console.Write("CPU usage at node " + i +  
                      " CPU " + j + ": "); 
        Console.Write(network_nodes[i][j] + "% ");  
        Console.WriteLine();  
      } 
      Console.WriteLine();  
    } 
 
  }  
}

           
         
  








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.illustrates the use of a two-dimensional rectangular arrayillustrates the use of a two-dimensional rectangular array
8.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
9.the use of a three-dimensional rectangular arraythe use of a three-dimensional rectangular array
10.the use of a jagged arraythe use of a jagged array
11.Uses a two-dimensional array to store grades for studentsUses a two-dimensional array to store grades for students
12.Uses a jagged array to store sales figuresUses a jagged array to store sales figures
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