How to sort a list with the values of another list with Linq

maje90

I have a list of parameters:

List<double> parameters = new List<double>() { 3.56, 8.9, 1.7, 0.5, 4.69 };

And a list of generic objects:

List<object> objects= new List<object>() { objA, objB, objC, objD, objE };

How can I sort "objects" list accordingly with the sorting of "parameters" list?

Cosmoleon

You can use the Linq function OrderBy to sort the objects using their respective index in the parameters list as a key.

List<double> parameters = new List<double>() { 3.56, 8.9, 1.7, 0.5, 4.69 };
List<object> objects = new List<object>() { objA, objB, objC, objD, objE };

objects = objects.OrderBy(x => parameters[objects.IndexOf(x)]).ToList();

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to sort a list according to another list? Python

분류에서Dev

Linq, Joining a list to last item in another list

분류에서Dev

How to sort a list of char[]?

분류에서Dev

How to iterate through a list and while iterating, iterate through another list and replace values for upper list with inner list key value pairs

분류에서Dev

How To Sort ArrayList in Different List

분류에서Dev

how to add one list with another list?

분류에서Dev

How to assign a list of values to an element of a list

분류에서Dev

Flutter: how to sort a List of Map on basis of value?

분류에서Dev

How to Sort a list for a specific case c#

분류에서Dev

How to match keys in a dictionary with the elements in a list and store those key values to another dictionary in python?

분류에서Dev

To-do list and sort

분류에서Dev

Sort dropdown list

분류에서Dev

Insertion Sort with a Linked List

분류에서Dev

Sort list dynamically on Excel

분류에서Dev

Translating a list to another list in prolog

분류에서Dev

python: How to compare values in a list by row?

분류에서Dev

How to get all values from a list?

분류에서Dev

How to create map with key and a list of values in JavaScript

분류에서Dev

How to sort list items by substring value ? c#

분류에서Dev

How to custom sort a multidimensional list with given label in Python

분류에서Dev

How to replace values in an object with values from a list in Javascript?

분류에서Dev

How to get list of class properties into string using LINQ?

분류에서Dev

How to fetch all the first records of different date in a list using linq

분류에서Dev

Remove all but the highest value from a List grouped by another property using LINQ

분류에서Dev

How to find a sub-list of two consecutive items in a list using Linq

분류에서Dev

Sort python dictionary with list as value

분류에서Dev

Sort List of Parent / Child Objects

분류에서Dev

JavaScript sort items list by months

분류에서Dev

LINQ get List <string> from List <List <string >> with any

Related 관련 기사

  1. 1

    How to sort a list according to another list? Python

  2. 2

    Linq, Joining a list to last item in another list

  3. 3

    How to sort a list of char[]?

  4. 4

    How to iterate through a list and while iterating, iterate through another list and replace values for upper list with inner list key value pairs

  5. 5

    How To Sort ArrayList in Different List

  6. 6

    how to add one list with another list?

  7. 7

    How to assign a list of values to an element of a list

  8. 8

    Flutter: how to sort a List of Map on basis of value?

  9. 9

    How to Sort a list for a specific case c#

  10. 10

    How to match keys in a dictionary with the elements in a list and store those key values to another dictionary in python?

  11. 11

    To-do list and sort

  12. 12

    Sort dropdown list

  13. 13

    Insertion Sort with a Linked List

  14. 14

    Sort list dynamically on Excel

  15. 15

    Translating a list to another list in prolog

  16. 16

    python: How to compare values in a list by row?

  17. 17

    How to get all values from a list?

  18. 18

    How to create map with key and a list of values in JavaScript

  19. 19

    How to sort list items by substring value ? c#

  20. 20

    How to custom sort a multidimensional list with given label in Python

  21. 21

    How to replace values in an object with values from a list in Javascript?

  22. 22

    How to get list of class properties into string using LINQ?

  23. 23

    How to fetch all the first records of different date in a list using linq

  24. 24

    Remove all but the highest value from a List grouped by another property using LINQ

  25. 25

    How to find a sub-list of two consecutive items in a list using Linq

  26. 26

    Sort python dictionary with list as value

  27. 27

    Sort List of Parent / Child Objects

  28. 28

    JavaScript sort items list by months

  29. 29

    LINQ get List <string> from List <List <string >> with any

뜨겁다태그

보관