Sorting Collections
Learn about sorting collections, and options for automatically sorted collections, and explore more specialized collections for efficient list operations.
Sorting with List<T>
A List<T>
class can be sorted by manually calling its Sort
method (but remember that the indexes of each item will change). Manually sorting a list of string
values or other built-in types will work without extra effort on our part, but if we create a collection of our own type, then that type must implement an interface named IComparable
.
No sorting for Stack<T>
and Queue<T>
A Stack<T>
or Queue<T>
collection cannot be sorted because we wouldn’t usually want ...