我正在开发一个小音乐应用程序,我正在其中填写一个下拉列表。
我的问题出在我在这里运行的 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/