I have a Dictionary <string, string>
where the value is a concatenation of substrings delimited with a :
. For example, 123:456:Bob:Smith
.
I would like to order the dictionary by the last substring (Smith) ascending, and preferably like this:
orderedDictionary = unordered
.OrderBy(x => x.Value)
.ToDictionary(x => x.Key, x => x.Value);
So, I need to somehow treat the x.Value
as a string
and sort by extracting the fourth substring. Any ideas?
var ordered = unordered.OrderBy(x => x.Value.Split(':').Last())
.ToDictionary(x => x.Key, x => x.Value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With