c# - How to efficiently limit and then concatenate a result with a linq / lambda expression? -
i in process of creating service create easy user select protocol iana - protocol registry.
as might imagine searching registry term http
pulls lot of hits. since amt-soap-http
going selected user much less straight http
decided thought pull out starts http
, concatenate remaining results.
the below lambda look result of thought process:
var records = this._ianaregistryservice.getalllike(term).tolist(); var results = records.where(r => r.name.startswith(term)) .orderby(r => r.name) .concat(records.where(r => !r.name.startswith(term)) .orderby(r => r.name)) .take(maxresultsize);
unfortunately, sense iterating through results more times necessary. premature optimization considerations aside there combination of lambda expressions more efficient above?
it might more efficient two-step ordering:
var results = records.orderby(r => r.name.startswith(term) ? 1 : 2) .thenby(r => r.name) .take(maxresultsize);
c# lambda concat
No comments:
Post a Comment