LINQ OrderBy not ordering .. changing nothing .. why?

前端 未结 1 2003
孤街浪徒
孤街浪徒 2020-11-29 12:09

Any idea why the LINQ OrderBy is not working in following code, (have no errors but method does not sort ...)

First my own type

public class IQLinksV         


        
相关标签:
1条回答
  • 2020-11-29 12:43

    Don't throw away the return value. The OrderBy extension method is does not mutate the input. Try:

    newView = newView.OrderBy(x => x.viewed);
    

    There is no reason why that won't work, assuming the viewed value is correct. Also, make sure that OrderBy is after any operations (e.g. Distinct) which will ruin ordering.

    Happy coding!

    0 讨论(0)
提交回复
热议问题