zoukankan      html  css  js  c++  java
  • .net 自然排序方式

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace ConsoleApplication12
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                string[] str = new string[] { "A1", "A2", "A10" };
                Array.Sort(str, new CustomComparer());
                for (int i = 0; i < str.Length; i++)
                    Console.WriteLine(str[i]);
            }
        }
    
        public class CustomComparer : System.Collections.IComparer
        {
            public int Compare(object x, object y)
            {
                string s1 = (string)x;
                string s2 = (string)y;
                if (s1.Length > s2.Length) return 1;
                if (s1.Length < s2.Length) return -1;
                for (int i = 0; i < s1.Length; i++)
                {
                    if (s1[i] > s2[i]) return 1;
                    if (s1[i] < s2[i]) return -1;
                }
                return 0;
            }
        }
    
    
    }
  • 相关阅读:
    css3基础篇二
    css3基础篇一
    react基础篇六
    react基础篇五
    react基础篇四
    react基础篇三
    react基础篇二
    react基础篇一
    矩阵
    POJ 3071 Football
  • 原文地址:https://www.cnblogs.com/guozhe/p/3527937.html
Copyright © 2011-2022 走看看