Why is List<>.OrderBy LINQ faster than IComparable+List<>.Sort in Debug mode?

前端 未结 4 2199
情歌与酒
情歌与酒 2021-02-19 11:30

I was interested in whether it would be faster to sort my classes using LINQ, or by implementing the IComparable interface and List.Sort. I was quite surprised when the LINQ cod

4条回答
  •  猫巷女王i
    2021-02-19 11:57

    Sort uses unoptimized quicksort, which has a n*n complexity in its worst case. I don't know what orderby uses but I know it doesn't use the same method since it's a stable sort, unlike array.sort.

提交回复
热议问题