To sort a List in C#, you can use the built-in List.Sort()
method, which uses an implementation of the QuickSort algorithm. Here is an example:
main.cs183 chars10 lines
If you have a custom object that you want to sort based on a specific property, you can use the overload of List.Sort()
that takes a Comparison<T>
delegate. Here is an example:
main.cs547 chars22 lines
In this example, we sort the peopleList
by the Name
property of each Person
object, using a lambda expression as the comparison function. You could also sort by Age
, or any other property of the Person
class.
gistlibby LogSnag