不得不也写了个排序。 先用着。有空再改进。
structs.Sort(new Comparison((t1, t2) => { var i = 0; var n1 = t1.ColName.ToLower(); var n2 = t2.ColName.ToLower(); while (n1.Length > i + 1 && n2.Length > i + 1 && n1[i] == n2[i]) { i++; } if (n1[i] > n2[i]) return 1; if (n1[i] < n2[i]) return -1; if (n1.Length < n2.Length) return -1; if (n1.Length > n2.Length) return 1; return 0; }));
public int CompareTo(object obj) { if (obj is TableStruct) { var t1 = this; var t2 = (TableStruct)obj; var i = 0; var n1 = t1.ColName.ToLower(); var n2 = t2.ColName.ToLower(); while (n1.Length > i + 1 && n2.Length > i + 1 && n1[i] == n2[i]) { i++; } if (n1[i] > n2[i]) return 1; if (n1[i] < n2[i]) return -1; if (n1.Length < n2.Length) return -1; if (n1.Length > n2.Length) return 1; return 0; } else { throw new Exception("不能比较"); } }