I have a text file being read into a string[] containing the days Monday to Friday, but in a random order. I want to sort them so they appear as they do in a calendar week.
I've tried Array.Sort() and Array.Reverse() but they don't work.
Any ideas?
Just sort it by the corresponding value of enum DayOfWeek of your string, then return it back to a string.
string [] initialArray = {"Friday", "Monday", ... } ;
string [] sortedArray = initialArray.OrderBy(s => Enum.Parse(typeof(DayOfWeek), s)).ToArray() ;
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