List.Sort(自定义排序...) [英] List.Sort (Custom sorting...)

查看:1686
本文介绍了List.Sort(自定义排序...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个List对象,其中包括3项:部分,全额H,并全额0

I have a List object that includes 3 items: Partial, Full To H, and Full To O.

我在这个列表绑定到一个asp OptionButtonList,和它的排序是按字母顺序排列。不过,我想对列表进行排序如下所示:

I'm binding this list to an asp OptionButtonList, and it's sorting it in alphabetical order. However, I want to sort the list like the following:

全额H,部分,全部为0

Full To H, Partial, Full To O.

我怎样才能做到这一点?

How can I accomplish this?

推荐答案

Linq的是为这个伟大的。你甚至可以建立序为拥有它的飞行定义,因为排序的执行直到了ToList

Linq is great for this. You could even build the order sequence up to have it defined on the fly since the execution of the sort is not executed until the ToList.

 var sortedList = yourList.OrderBy(i => i.FullToH).
     ThenBy(i => i.Partial).
     ThenBy(i => i.FullToO).ToList();

这篇关于List.Sort(自定义排序...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆