Working with Multidimensional Arrays - CSharp Language Basics

CSharp examples for Language Basics:Array

Description

Working with Multidimensional Arrays

Demo Code

using System;/* w  ww. ja  v  a 2 s .c o  m*/
public class Names
{
   public static void Main()
   {
      char[][] name = new char[3][];
      name[0] = new char[7] {'B', 'r', 'a', 'd', 'l', 'e', 'y'};
      name[1] = new char[2] {'L', '.'};
      name[2] = new char[5] {'J', 'o', 'n', 'e', 's'};
      Console.WriteLine("Length of name array {0}", name.Length);
      for( int i = 0; i < name.Length; i++)
         Console.WriteLine("Length of name[{0}] is {1}", i, name[i].Length);
      Console.WriteLine("\nDisplaying the content of the name array...");
      for( int i = 0; i < name.Length; i++)
      {
         Console.Write("\n");  // new line
         for( int i2 = 0; i2 < name[i].Length; i2++ )
         {
            Console.Write("{0}", name[i][i2]);
         }
      }
      Console.WriteLine("\n...Done displaying");
   }
}

Result


Related Tutorials