C# 列表排序,包含字符、数字

复制代码
 public sealed class NaturalStringComparer : IComparer<string>
    {
        public static readonly NaturalStringComparer Default = new NaturalStringComparer();

        public int Compare(string x, string y)
        {
            return SafeNativeMethods.StrCmpLogicalW(x, y);
        }
    }

    [SuppressUnmanagedCodeSecurity]
    internal static class SafeNativeMethods
    {
        [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
        public static extern int StrCmpLogicalW(string psz1, string psz2);
    }
    
    //以下是调用的方法
    var listDate=new List<string>(){"a1",“a3”,"a2"}
var list= listDate.OrderBy(p => p, new NaturalStringComparer());
复制代码

 

 
 
posted @   宇宙无敌狗蛋  阅读(152)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
历史上的今天:
2022-02-17 C# this.Invoke()的作用与用法
点击右上角即可分享
微信分享提示