c# - Selecting items in an ordered list after a certain entry -


i have ordered list of objects. can find item in list using following code:

purchaseorders.firstordefault(x => x.ourref.equals(lastpurchaseorder, stringcomparison.ordinalignorecase)) 

what want select items in list appear after entry. how best achieve this? to index of item , select range?

it sounds want skipwhile:

var orders = purchaseorders.skipwhile(x => !x.ourref.equals(...)); 

once iterator has stopped skipping, doesn't evaluate predicate later entries.

note that code include entry doesn't match predicate, i.e. 1 given reference. give entries order onwards. can use .skip(1) if want skip that:

// skip exact match var orders = purchaseorders.skipwhile(x => !x.ourref.equals(...)).skip(1); 

this linear, mind you... if list ordered x.ourref find index binary search , take range there onwards... wouldn't unless find simpler code causes problems.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -