C#匿名实现IComparer接口-按指定字符串规则排序
作者:互联网
需要将数组["丁","乙","甲","丙"],按甲、乙、丙、丁排序,但是C#的字符串排序规则没有该排序类型,所以预指定顺序,再匿名生成IComparer接口的实现类。
var classOrderList = new List<string>{"甲","乙","丙","丁"}; var comparer = Comparer<string>.Create((k1, k2) => classOrderList.IndexOf(k1) - classOrderList.IndexOf(k2));
标签:IComparer,k2,C#,IndexOf,匿名,classOrderList,排序 来源: https://www.cnblogs.com/xyzdl/p/16277858.html