Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    Demonstrations of array types in C#.Lecture 2 - slide 10 : 43
Program 1
using System;

class ArrayStringDemo{

  public static void Main(){
     string[]  a1,                          
               a2 = {"a", "bb", "ccc"};     

     a1 = new string[]{"ccc", "bb", "a"};   

     int[,]    b1 = new int[2,4],           
               b2 = {{1,2,3,4}, {5,6,7,8}}; 

     double[][] c1 = { new double[]{1.1, 2.2},               
                       new double[]{3.3, 4.4, 5.5, 6.6} };

     Console.WriteLine("Array lengths. a1:{0} b2:{1} c1:{2}",    
                        a1.Length, b2.Length, c1.Length);        

     Array.Clear(a2,0,3);                                        

     Array.Resize<string>(ref a2,10);                           
     Console.WriteLine("Lenght of a2: {0}", a2.Length);         

     Console.WriteLine("Sorting a1:");                          
     Array.Sort(a1);
     foreach(string str in a1) Console.WriteLine(str);          
  }   

}
 
 
 
 
 
Not initialized (not even null).
An array with 3 strings.
 
a1 is initialize to a string array.
 
2 rows, 4 columns, all initialized to default(int)
2 rows, 4 columns, explicitly initialized.
 
a jagged array, explicitly initialized.
 
 
Length operation from System.Array.
a1:3 b2:8 c1:2
 
Set a[0], a[1], a[2] to their default values.
 
Resize operation from System.Array. 
10. Reveals successful resizing.
 
Sort operation from System.Array.
 
a bb ccc