I am trying to sort a list of strings in an order that is pertinent to a sequence used in common revision history sequences. Some customers start with "-", or "New", or a few other specific codes, and I can use LINQ to define a custom sort order. However, after a drawing has been revised from Rev A all the way through Rev Z, it becomes Rev AA through Rev AZ, then Rev BA through BZ and so forth. How can I sort the following list using LINQ?
I have this as an example block of code:
List<string> revList = new List<string> { "A", "NC", "New", "AB", "PD", "PD1",
"PD2", "B", "-", "*", "BB", "NA" };
revList = revList.OrderByDescending(i => i.ToLower() == "pd").
ThenByDescending(i => i.ToLower() == "nc").
ThenByDescending(i => i.ToLower() == "na").
ThenByDescending(i => i.ToLower() == "new").
ThenByDescending(i => i.ToLower() == "pd1").
ThenByDescending(i => i.ToLower() == "pd2").
ThenByDescending(i => i.ToLower() == "-").
ThenByDescending(i => i.ToLower() == "*").
ThenBy(i => i).ToList();
foreach (string rev in revList)
Console.WriteLine(rev);
This produces output as:
PD
NC
NA
NEW
PD1
PD2
-
*
A
AB
B
B
I would like to produce:
PD
NC
NA
NEW
PD1
PD2
-
*
A
B
AB
BB
Lengthfirst, e.g. insertThenBy(i => i.Length).beforeThenBy(i => i)PDcome beforeNCis the desired results?