Skip to main content

In one of our previous articles we described how to add values to ComboBox together with Ids in C# using class for keeping Id and Value.

Simillar to this logic, you can easily find yourself in a situation that you need to sort values in the list by some of the class property.

Here is, by our opinion, the easiest way for sorting a list collection of classes by some of its properties in C#. In this example we'll use "Name" as a class' property.

// Create the list
List<TestClass> testList = new List<TestClass>();
 
...
// Populate the list
...
 
// Sort the list by some property
testList = testList.OrderBy(p => p.Name).ToList();

- Advertisement -
- Advertisement -