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

2023-09-03 08:52:49 作者:遗忘

我型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.