Order by vs Sort to create a custom collection

I went through this C # article Sorting and Comparing OrderBy

But the answer accepted in this question is not clear to me.

I cannot decide when to use Sort or when I should use OrderBy.

In any case, it is recommended that you sort or order one above the other.

So please give me a short answer without any complications.

+6
source share
1 answer
  • You use Sort if you want to sort the source list. It performs sorting in place.
  • You use OrderBy when you do not want to modify the original list, when it returns an IOrderedEnumerable<T> , which does not contain the original list. Or, when you do not have a list, except for some other enumerated ones.
+22
source

Source: https://habr.com/ru/post/945134/


All Articles