Вопрос по generics, sorting, c# – Выборочная сортировка списка

3

Error: User Rate Limit ExceededList<T>Error: User Rate Limit ExceededTError: User Rate Limit ExceededEventError: User Rate Limit ExceededtimeError: User Rate Limit ExceededlongError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

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);

Error: User Rate Limit ExceededIComparerError: User Rate Limit Exceeded

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;
    }
}

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Ваш Ответ

5   ответов
1

Error: User Rate Limit Exceeded0 == 3Error: User Rate Limit Exceeded3 > 0Error: User Rate Limit Exceeded0 > 3Error: User Rate Limit Exceeded3 < 0Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

if (x.time == y.time) return 0;
if (x.time == 0) return 1;
if (y.time == 0) return -1;
return x.time.CompareTo(y.time);
2

Error: User Rate Limit Exceeded

resp.OrderBy(i => i.time == 0 ? int.MaxValue : i.time);
Error: User Rate Limit Exceeded earthling
1

Error: User Rate Limit Exceeded

    class Comparer : IComparer<int>
    {
        public int Compare(int x, int y)
        {
            if (x == y) return 0;
            else if (x == 0) return 1;
            else if (y == 0) return -1;
            else if (x < y) return -1;
            else if (x > y) return 1;
        }
    }
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit ExceededelseError: User Rate Limit Exceededreturn
Error: User Rate Limit Exceeded.Compare(0, 0)Error: User Rate Limit Exceeded0Error: User Rate Limit Exceeded1.
1

Error: User Rate Limit Exceeded

 if(x.time==y.time) return 0;
 if(x.time==0) return 1;
 return x.time - y.time;

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded earthling
11

Error: User Rate Limit Exceeded

   events.OrderBy (e => e.Time == 0).ThenBy (e => e.Time);
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded

Похожие вопросы