Sort array sử dụng comparison
Sort Array C# 2016
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SortCompareToComparison
{
class Program
{
private static int ComapreTo(string a, string b)
{
return a.Length.CompareTo(b.Length);
}
static void Main(string[] args)
{
string[] array =
{
"Yll",
"Al",
"L",
"Dooo",
"B",
};
foreach(string a in array){
Console.WriteLine(a);
}
Console.WriteLine("----------------");
Comparison<String> com = new Comparison<string>(ComapreTo);
Array.Sort(array, ComapreTo);
foreach (string a in array)
{
Console.WriteLine(a);
}
Console.Read();
}
}
}
0 nhận xét:
Post a Comment