Exercises in this lecture   Go to the notes, in which this exercise belongs -- Keyboard shortcut: 'u'   Alphabetic index   Course home   

Exercise solution:
Use of array types


Here is my solution:

using System;

class StringTry{

  public static void Main(){

    string[] group = {"Kurt", "Peter", "Paul", "Mary"};

    foreach(string name in group)
      Console.WriteLine(name);       // Kurt Peter Paul Mary

    Console.WriteLine();

    Array.Sort(group); 
    foreach(string name in group)
      Console.WriteLine(name);       // Kurt Mary Paul Peter

    int res = Array.BinarySearch(group, "Mary");
    Console.WriteLine(res);          // 1

    Console.WriteLine();

    Array.Reverse(group);
    foreach(string name in group)
      Console.WriteLine(name);       // Peter Paul Mary Kurt
 
  }

}