private ICollection <Product> FindTopProductsByPrice(OrderedBag <Product> productList, double startPrice, double endPrice) { var firstProductStartPrice = productList.FirstOrDefault(x => x.Price >= startPrice); var lastProductEndPrice = productList.LastOrDefault(x => x.Price <= endPrice); var productsInRange = productList.Range(firstProductStartPrice, true, lastProductEndPrice, true); var firstgivenProductsInRange = productsInRange.Take(ProductsInRangeCount); return(firstgivenProductsInRange.ToList()); }
static IEnumerable<Product> GetProductsByPriceRange(OrderedBag<Product> products, decimal from, decimal to, int count) { var result = products.Range( products.FirstOrDefault(x => x.Price >= from), true, products.LastOrDefault(x => x.Price <= to), true).Take(count); return result; }