Custom sorting with LINQ

前端 未结 6 1122
被撕碎了的回忆
被撕碎了的回忆 2021-01-15 04:16

It seems that i\'m missing something trivial.

Anyway, here it goes:

var order = new[]{1,3,2};
var foos = new[]{new Foo{Id=1}, new Foo{Id=2}, new Fo         


        
6条回答
  •  孤城傲影
    2021-01-15 04:36

    Is this what you are trying to do?

    foos.OrderBy(f => order[f.Id-1]);
    

    If you foreach now on the output of that, printing the ID, you get: 1,3,2

提交回复
热议问题