gpt4 book ai didi

c# - 如何在 linq 中排序项目类别

转载 作者:太空狗 更新时间:2023-10-30 00:23:51 25 4
gpt4 key购买 nike

我有20条记录

我想根据 Priority 字段对记录进行排序。

Priority 字段有 3 个值(High、Medium、Low)

我想依次显示High, Medium, Low记录中的记录。

var groupedRecords = records.GroupBy(x => x.Priority == "High") // confused here...

注意:我想获取首先所有高记录,然后中记录和最后低记录。

最佳答案

为什么不将优先级映射为整数:

  High   -> 1
Medium -> 2
Low -> 3

所以它可以是这样的:

  var groupedRecords = records.
OrderBy(x => (x.Priority == "High")
? 1
: (x.Priority == "Medium") ? 2 : 3);

关于c# - 如何在 linq 中排序项目类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33867468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com