• c#字符串按照1.1,1.1.1,2.1,2.1.1排序


     List<string> list = new List<string> { "1", "1.1", "1.1.1", "1.1.2", "1.1.3", "1.2", "1.3", "2", "2.1", "2.2", "2.3", "2.3", "1" };
                list.Sort((x, y) =>
                    {
                        int ret = 0;
                        var xsplit = x.Split(".".ToCharArray()).Select(z => int.Parse(z)).ToList();
                        var ysplit = y.Split(".".ToCharArray()).Select(z => int.Parse(z)).ToList();
                        for (int i = 0; i < Math.Max(xsplit.Count, ysplit.Count); i++)
                        {

                            if (xsplit.Count - 1 < i)
                            {
                                ret = -1;
                                return ret;
                            }
                            else if (ysplit.Count - 1 < i)
                            {
                                ret = 1;
                                return ret;
                            }
                            else
                            {
                                ret = xsplit[i] - ysplit[i];
                                if (ret != 0)
                                    return ret;
                            }
                        }
                        return  ret;

                    });
            }

  • 相关阅读:
    使用ParseExact方法将字符串转换为日期格式
    Windows 备用数据流(ADS)的妙用___转载
    ms17_010利用复现(32位)
    将手机号设置为空号
    PowerShell批量创建文件夹
    让程序显示运行时间
    使用Sleep方法延迟时间
    使用TimeSpan对象获取时间间隔
    DateTime小综合
    DDMS介绍
  • 原文地址:https://www.cnblogs.com/xlxr45/p/16289003.html
Copyright © 2020-2023  润新知