如何排序泛型列表ASC或DESC? [英] How to sort Generic List Asc or Desc?

查看:194
本文介绍了如何排序泛型列表ASC或DESC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我型MyImageClass的通用集合,MyImageClass有一个布尔属性IsProfile。我想这个排序泛型列表这IsProfile ==在列表开始真正的看台上。

I have a generic collection of type MyImageClass, and MyImageClass has an boolean property "IsProfile". I want to sort this generic list which IsProfile == true stands at the start of the list.

我已经试过这一点。

rptBigImages.DataSource = estate.Images.OrderBy(est=>est.IsProfile).ToList();

与code以上的图像,在这IsProfile属性为true的最后一个代表。 但我想这是第一个索引。我需要的东西的 ASC或DESC 的。然后我做了这一点。

with the code above the image stands at the last which IsProfile property is true. But i want it to be at the first index. I need something Asc or Desc. Then i did this.

rptBigImages.DataSource = estate.Images.OrderBy(est=>est.IsProfile).Reverse.ToList();

有没有更简单的方式来做到这一点?

Is there any easier way to do this ?

感谢

推荐答案

怎么样:

estate.Images.OrderByDescending(est => est.IsProfile).ToList()

这将指令中的图像由IsProfile物业降序排列,然后创建结果的新列表。

This will order the Images in descending order by the IsProfile Property and then create a new List from the result.

这篇关于如何排序泛型列表ASC或DESC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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