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());