//play with arrays class playwitharrays { static void Main(string[] args) { string[] friends = new string[] { "John", "Amy", "Rose", "Lisa", "Alen" }; //display elements of the array Console.WriteLine("Elements of String array"); foreach (string str in friends) Console.Write(str+" "); Console.WriteLine(); Console.WriteLine("Number of elements in the array: " + friends.Length); Console.WriteLine("This array is a " + friends.Rank + " dimensional array"); //display elements of the array in reverse order Console.WriteLine("Elements of String array (reverse)"); Array.Reverse(friends); foreach (string str in friends) Console.Write(str+" "); Console.WriteLine(); //display elements of the array in sorted order Console.WriteLine("Elements of String array (sorted)"); Array.Sort(friends); foreach (string str in friends) Console.Write(str+ " "); Console.ReadKey(); } }
Elements of String arrayJohn Amy Rose Lisa AlenNumber of elements in the array: 5This array is a 1 dimensional arrayElements of String array (reverse)Alen Lisa Rose Amy JohnElements of String array (sorted)Alen Amy John Lisa Rose