本文介绍了C#列表排序的两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我需要通过两个不同的变量进行排序的是一个布尔值,另一个是一个字符串C#自定义对象名单。我可以排序的或者的的标准,但我无法搞清楚如何把它们结合起来。排序应该是所有的布尔值第一(CheckedIn),然后对每个值的姓氏。现在,我用
result.Sort((X,Y)=>的String.Compare(x.CheckedIn.ToString( ),y.CheckedIn.ToString())); result.Sort((X,Y)=>的String.Compare(x.LastName,y.LastName));
但我怎么能结合则使我的结果是像
CheckedIn-名称无 - 艾姆斯无 - 史密斯是 - 巴恩斯是 - 彼得斯解决方案
result.Sort((X ,Y)=> x.CheckedIn == y.CheckedIn 的String.Compare(x.LastName,y.LastName):(x.CheckedIn -1:1));
I have a C# custom object list that I need to sort by two different variables one is a boolean and the other is a string. I can sort by either of the criteria, but I'm having trouble figuring out how to combine them. The sort should be all of the boolean values first (CheckedIn) and then the last name for each of the values. Right now I use
result.Sort((x, y) => string.Compare(x.CheckedIn.ToString(), y.CheckedIn.ToString())); result.Sort((x, y) => string.Compare(x.LastName, y.LastName));But how can I combine then so that my results are like
CheckedIn-Name No - Aames No - Smith Yes - Barnes Yes - Peters解决方案 result.Sort((x,y) => x.CheckedIn==y.CheckedIn ? string.Compare(x.LastName, y.LastName) : (x.CheckedIn ? -1 : 1) );
更多推荐
C#列表排序的两列
发布评论