I have a list that contains an object. The object has a string property called AppointmentTime
. This is used in my view, Arguably this may be better as a DateTime property using stringFormat on the binding.
So my objects may have an AppointmentTime that looks Something like this:
Object1.AppointmentTime = "12.41"
Object2.AppointmentTime = "13.49"
Object3.AppointmentTime = ""
Object4.AppointmentTime = "9.43"
I now want to sort this list by this property, with the empty strings at the bottom of the list
So far I have tried:
ListofObjects.OrderBy(x => Convert.ToDecimal(x.AppointmentTime);
but without luck... Any ideas?
EDIT - My Solution
As someone in the comment very kindly pointed out. Using the OrderBy creates a new list and does not order the original list. Silly Microsoft, should warn you that you have not set the new list equal to anything. My Final Solution was:
diaryEntries = new ObservableCollection<DiaryEntryViewModel>(diaryEntries.OrderBy(x => x.AppointmentTime).OrderBy(x => string.IsNullOrEmpty(x.AppointmentTime)));
Although I feel the longterm solution is to change this property to a DateTime as suggested