Working with lists is something developers do almost everyday. One of the most common tasks when we think about lists is sorting them. Fortunately, sorting lists in C# is not very complicated when it comes to primitive types and strings, but are slightly more complicated when we create lists of our own objects. In this tutorial we’ll go through some of the common ways to sort lists in C#.
Update: I have also created a video on this topic so if you think that it’s easier to follow the video, here it is:
Let’s start with a short and simple example. Let’s assume that we create a list of names and we add some names to the list:
List<string> names = new List<string>(); names.Add("John"); names.Add("Dan"); names.Add("Zack"); names.Add("Cristina");