c# - Removing an object from IOrderedEnumerable -
i sorted dictionary this:
var sortedlistofnodes = _nodedictionary.values.orderby((n) => n.time);
then selected element such:
var selectednode = sortedlistofnodes.first(n => n.time - currenttime > new timespan(1,0,0));
then did processing on node , @ end wanted remove node list, without destroying sorted order.
would below maintain order?
sortedlistofnodes = (iorderedenumerable<node>)sortedlistofnodes.where(node => node != selectednode);
add call tolist
after orderby
. have list can manipulate (assuming don't insert items stay in order).
var sortedlistofnodes = _nodedictionary.values.orderby((n) => n.time).tolist(); var selectednode = sortedlistofnodes.first(n => n.time - currenttime > new timespan(1,0,0)); sortedlistofnodes.remove(selectednode);
on side note example of casting result of where
iorderedenumerable<node>
fail @ runtime casting failure. where
calling concrete type not implement interface.
Comments
Post a Comment