• 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;

                    });
            }

  • 相关阅读:
    聊天工具分享bug
    Git命令查看代码提交次数
    短链接生成实例
    .Net MVC用户注册验证码
    js写验证码
    笔记
    jq获取数组中的某个字段拆分成字符串。
    IIS部署后中文Cookie乱码
    C#反射(Reflection)与特性(Attribute)实例
    jmm
  • 原文地址:https://www.cnblogs.com/xlxr45/p/16289003.html
Copyright © 2020-2023  润新知