i have store 100k items. each of them contains two values (fields?)
datetime, decimal
i have sort these items datetime
values well. however, try failed compile-time error:
list<datetime, decimal> list = ... // <- compile time error ... list.sort();
how can solve problem of storing , sorting such items? possible using linq?
first, can't declare list<t>
that
list<datetime, decimal> list // compile time error
since list<t>
can have only one generic parameter (that's t
). most, probably, popular solution using
tuple<t1, t2, ...>
in case
tuple<datetime, decimal>
so implementation be
list<tuple<datetime, decimal>> list = new list<tuple<datetime, decimal>>() { new tuple<datetime, decimal> (datetime.now, 2), new tuple<datetime, decimal> (datetime.now, 1), new tuple<datetime, decimal> (datetime.now, 3), }; // sorting existing list list.sort((comparison<tuple<datetime, decimal>>) ((left, right) => left.item1.compareto(right.item1))); // create (sorted) list linq: list<tuple<datetime, decimal>> result = list .orderby(item => item.item1);
Comments
Post a Comment