public static OrderedBag<Product> FillProducts() { var bag = new OrderedBag<Product>((x,y) => x.Price.CompareTo(y.Price)); for (int i = 0; i < 500000; i++) { var product = new Product("Product#" + i, i); bag.Add(product); } return bag; }
public static Product[] GetProductsInRange(decimal lowestPrice, decimal highestPrice, int count, OrderedBag<Product> data) { var cheapestProduct = new Product("", lowestPrice); var mostExpensiveProduct = new Product("", highestPrice); var matches = data.Range(cheapestProduct, true, mostExpensiveProduct, true); if (matches.Count <= count) { return matches.ToArray(); } var result = new Product[count]; for (int i = 0; i < count; i++) { result[i] = matches[i]; } return result; }