class StringComparer : IComparer<string>
{
public int Compare(string str1, string str2)
{
for (int i = 0; i < str1.Count; ++i)
{
if (str1[i] > str2[i])
{
return 1;
}
if (str1[i] < str2[i])
{
return -1;
}
}
return 0;
}
}
using System;
namespace strsort
{
class Program
{
public static void Main(string[] args)
{
//данный массив строк
string[] m = {"a","abc","ab"};
Console.WriteLine("Массив до сортировки:");
foreach (string s in m)
Console.WriteLine(s);
Array.Sort(m);
Console.WriteLine();
Console.WriteLine("Массив после сортировки:");
foreach (string s in m)
Console.WriteLine(s);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
using System;
using System.Linq;
public class Program
{
public static void Main()
{
string[] __sa = {"a", "abc", "ab"};
Console.WriteLine(String.Join(" ", __sa.OrderBy(x => x.Length).ToArray()));
}
}