Sort a list according to another list

后端 未结 5 1638
慢半拍i
慢半拍i 2020-12-21 12:29

I have a list1 like this :

{A,B,C,D,E,F}

I have another list2 that list2 count is equal with l

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-21 12:52

    Try this:

    int index = 0;
    list1 = list1.OrderBy(d => list2[index++]).ToList();
    

    It should produce the expected result given the following two lists:

    List list1 = new List { "A", "B", "C", "D", "E", "F" };
    List list2 = new List { 50, 100, 14, 57, 48, 94 };
    

提交回复
热议问题