您的位置:首页 > 其它

排序含有数字的字符串:一个巧妙地方法【转】

2014-09-30 15:26 225 查看
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;
}
}

转自:http://www.cnblogs.com/smiler/archive/2014/09/29/4000662.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐