文章出處

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

 


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()