Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
And standard sorting does not want to sort them?
If not, then make your own IComparer and pass it to the standard sort.
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);
}
}
}
Discover LINQ:
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()));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question