1

I have a list of Item objects (C#):

List itemList.

the Item object has a property Title, with values varying between ("Article 3:", "Article 14:", "Article 233: dfsdf", etc).

when I sort in the regular LINQ way, like this:

itemList.OrderBy(p => p.Title).ToList();

Article 14 is sorted before Article 3, because it starts with 1. How do I sort this collection in the right way?

stefjnl
  • 732
  • 3
  • 14
  • 31

1 Answers1

2

You can define a property with a getter only on the Object, that will load from the Title just the numbers (maybe by splitting the title by " ", or by replacing the Article text, then trimming the result ), and use the new property in the OrderBy.

Andrei Filimon
  • 1,138
  • 8
  • 12