Clasificación personalizada de la lista <T>
tengo unList<T>
dóndeT
es miEvent
tipo que tiene un campotime
de tipolong
. Esta lista se rellena desde un servicio web y si un evento no tiene una hora, el valor establecido es 0.
Lo que quiero hacer es ordenar mi lista ascendente por tiempo, pero colocar los elementos con tiempo = 0 en la parte inferior.
Actualmente estoy logrando esto de una manera un tanto hack y quiero aprender de una mejor manera.
<code>var events = new ObservableCollection<Event>(); var resp = JsonConvert.DeserializeObject<Events>(restResponse.Content).Items; var notime = resp.Where(r => r.time == 0); var yestime = resp.Where(r => r.time > 0); yestime.ToList().ForEach(events.Add); notime.ToList().ForEach(events.Add); CallbackInternal(callback, events); </code>
Intenté implementar una costumbre.IComparer
, pero eso no funcionó tan bien (aquí hay una oportunidad)
<code>public class EventComparer : IComparer<Event> { public int Compare(Event x, Event y) { if (x.time == 0) return 0; if (x.time < y.time) return -1; if (x.time > y.time) return 1; return 0; } } </code>
Se aprecia la orientación!
¡Gracias!