using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { /// /// Contains the string array we use. /// static class StringObjects { /// /// An array of strings we want to sort or process. /// public static string[] _sortArrays = new string[] { "Egyptian", "Indian", "American", "Chinese", "Filipino", "Indonesian", "Korean", "Japanese", "English", "German", "French", "Italian", "European", "Irish", "Vietnamese", "Australian", "Mongolian", "Russian", "Austrian", "Brazilian", "El Salvadorian", "Kenyan", "Rwandan", "Icelandic", "African", "French", "Spanish", "Antarctic", "Canadian", "Mexican", "Swedish", "Polish", "Israeli", "Turkish", "Pakistani", "Belgian", "Iraqi", "Iranian", "Romanian", "Latvian", "Norwegian", "Ukrainian", "Chilean", "Liberian", "Libyan", "Nicaraguan", }; } /// /// The class that contains the string objects and methods. /// class StringSort { public StringSort() { Console.WriteLine(StringObjects._sortArrays.Length); } /// /// Return two arrays together. /// public string[] DoubleArray() { List half = new List(StringObjects._sortArrays); half.AddRange(StringObjects._sortArrays); return half.ToArray(); } /// /// Get ten arrays combined. /// public string[] TenArray() { List ten = new List(); for (int i = 0; i < 10; i++) { ten.AddRange(StringObjects._sortArrays); } return ten.ToArray(); } /// /// Get the array already sorted. /// public string[] AlreadySortedArray() { List already = new List(StringObjects._sortArrays); already.Sort(); return already.ToArray(); } /// /// Clone the array, then sort the clone. /// /// The input array. /// The sorted copy. public static string[] SortArray(string[] array) { string[] res = (string[])array.Clone(); Array.Sort(res); return res; } /// /// Use LINQ to get a sorted IEnumerable, then convert it to /// an array. /// /// The input string array. /// The new sorted array. public static string[] SortLinq(string[] array) { var res = from item in array orderby item ascending select item; return res.ToArray(); } /// /// Copy the List using the copy constructor. Then sort the copy. /// /// The input list. /// The sorted copy. public static List SortList(List list) { List res = new List(list); res.Sort(); return res; } } }