【发布时间】:2021-07-01 09:31:06
【问题描述】:
bookingInfo.CreditCardList = airUserCreditCardList
.Distinct()
.OrderBy(o => o.Text)
.ToList();
我正在尝试根据 Text 属性中的值对列表进行排序。有没有一种方法可以仅在对象的属性 Text 的值为“Primary”时才能对列表进行排序。
我的列表是这样的
Text="abc",Code="123"----0th index
Text ="Select",Code="1233"--1st Index
Text="Primary",Code="0000"--2ndIndex```
But i want it to look like this only if the Primary card is present in the list
```
Text="Primary",Code="0000"--0th Index
Text ="Select",Code="1233"--1st Index
Text ="abc",Code="123"--2nd Index
【问题讨论】:
-
您能否举一些例子说明“仅当 Text 的值为主要时才对列表进行排序,否则不应发生排序”?
-
不清楚,如果您只想按记录排序哪些文本是“主要”,您的意思是您想先查看所有“主要”信用卡然后休息?
-
不清楚什么是“如果
Text的值是主要的”。像这样的东西:.OrderBy(o => o.Text != "primary") -
如果“Primary”在列表中,为什么“abc”出现在“Select”之后?我知道“Primary”排在第一位,但如果您按
Text订购,则“abc”一词将位于“Select”之前。这也不是原来的顺序,所以似乎突然“abc”无缘无故地出现在最后。解释规则。
标签: c#