---
title: "如何排序含有数字的字符串"
author: "dqifa"
date: "2018-06-13T21:19:08Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2018-06-13T21:19:08Z"
id: 2424916
url: "https://emonkey.iteye.com/blog/2424916"
---

using System;

using System.Collections.Generic;

 

class Program

{

    static void Main(string\[] args)

    {

        string\[] floors ={ "第3次", "第2次", "第11次" };

        Array.Sort&lt;string&gt;(floors, Factory.Comparer);

        foreach (string s in floors)

            Console.WriteLine(s);

        Console.ReadKey();

    }

}

 

// 工厂模式

class Factory : IComparer&lt;string&gt;

{

    private Factory() { }

    public static IComparer&lt;string&gt; Comparer

    {

        get { return new Factory(); }

    }

    public int Compare(string x, string y)

    {

        return x.Length == y.Length ? x.CompareTo(y) : x.Length - y.Length;

    }

}

 

FROM:https://blog.csdn.net/fwj380891124/article/details/39693673