gpt4 book ai didi

c# - 用于按特定集列表排序的 LINQ 查询

转载 作者:行者123 更新时间:2023-11-30 20:34:25 25 4
gpt4 key购买 nike

我正在开发一个小音乐应用程序,我正在其中填写一个下拉列表。

我的问题出在我在这里运行的 LINQ 查询中:

var results = (from x in db.Keys
where x.SongId == songId
orderby x.ChordKey ascending
select x.ChordKey).ToList();

我的 ChordKey 值始终是:

Ab, A, Bb, B, C, C#, Db, D, Eb, E, F, F#, Gb, G

我希望它们按照上面的顺序排列,不幸的是,如果按字母顺序排列,A 将出现在 Ab 之前,等等。有没有办法按照上面的具体标准来订购?

最佳答案

对具有基础整数值的键使用枚举,以您想要的方式排序。

public enum ChordKey 
{Ab=1, A=2, Bb=3, B=4, C=5,
Db=6, D=7, Eb=8, E=9,
F=10, Gb=11, G=12}

然后

var results = (from x in db.Keys
where x.SongId == songId
orderby (int)x.ChordKey ascending
select x.ChordKey).ToList();

关于c# - 用于按特定集列表排序的 LINQ 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39243058/

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