如何排序泛型列表ASC或DESC?

编程入门 行业动态 更新时间:2024-10-22 07:25:22
本文介绍了如何排序泛型列表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?

本文发布于:2023-10-23 05:52:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519983.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:列表   ASC   DESC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!