如何排序含有数字的字符串

using System;
using System.Collections.Generic;
 
class Program
{
    static void Main(string[] args)
    {
        string[] floors ={ "第3次", "第2次", "第11次" };
        Array.Sort(floors, Factory.Comparer);
        foreach (string s in floors)
            Console.WriteLine(s);
        Console.ReadKey();
    }
}
 
// 工厂模式
class Factory : IComparer
{
    private Factory() { }
    public static IComparer Comparer
    {
        get { return new Factory(); }
    }
    public int Compare(string x, string y)
    {
        return x.Length == y.Length ? x.CompareTo(y) : x.Length - y.Length;
    }
}

你可能感兴趣的:(C#语言)