I am creating a service so that a user can select a protocol from the IANA-Protocol Registry .
As you can imagine, a registry search for a term httpcauses a lot of hits. Since the amt-soap-httpuser is going to select much less often than the direct one http, I decided that it would be nice to pull out everything that starts with http, and then combine this with the rest of the results.
The following lambda expression is the result of this 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, it seems to me that I repeat the results more often than necessary. Premature optimization considerations include a combination of lambda expressions that would be more efficient than higher?
source
share