本文整理汇总了C#中OrderedBag.FindAll方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedBag.FindAll方法的具体用法?C# OrderedBag.FindAll怎么用?C# OrderedBag.FindAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderedBag
的用法示例。
在下文中一共展示了OrderedBag.FindAll方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
OrderedBag<Item> catalog = new OrderedBag<Item>();
Random random = new Random();
for (int i = 0; i < 50000; i++)
{
catalog.Add(new Item("item" + i, random.Next(0, int.MaxValue)));
}
var prices = catalog.FindAll(x => x.Price > 100 && x.Price < 150);
for (int i = 0; i < 10000; i++)
{
int min = random.Next(0, int.MaxValue);
int max = random.Next(min, int.MaxValue);
prices = catalog.FindAll(x => x.Price > min && x.Price < max);
}
//print only the result of the last search becouse printing is very slow operation
int count = 20;
foreach (var item in prices)
{
Console.WriteLine("name:"+item.Name + "-> price:"+item.Price);
count -= 1;
if (count<=0)
{
break;
}
}
}
示例2: Main
public static void Main()
{
OrderedBag<Product> catalog = new OrderedBag<Product>();
for (int i = 0; i < 500000; i++)
{
catalog.Add(new Product("Product" + i, GetRandomNumber(39,709)));
}
var prices = catalog.FindAll(x => x.Price > 200 && x.Price < 350);
int count = 20;
StringBuilder sb = new StringBuilder();
foreach (var product in prices)
{
sb.AppendFormat("name: {0} -> price {1}", product.Name, product.Price);
sb.AppendLine();
count -= 1;
if (count <= 0)
{
break;
}
}
Console.WriteLine("Print results: ");
Console.WriteLine(sb.ToString());
}
示例3: Main
static void Main()
{
Console.WriteLine("Generating product's list...");
var produkts = new OrderedBag<Product>();
Random rnd = new Random();
for (int i = 0; i < 500000; i++)
{
int price = rnd.Next(1, 100001);
string name = "product-" + i;
Product product = new Product(name, price);
produkts.Add(product);
}
Console.WriteLine("Searching 20 products in range 10257 - 11336 lv");
Predicate<Product> isProduktInRange = p => p.Price >= 10257 && p.Price <= 11336;
var range = produkts.FindAll(isProduktInRange);
int count = 0;
foreach (var item in range)
{
Console.WriteLine(item);
++count;
if (count == 20)
{
return;
}
}
}
示例4: FindInRange
private static void FindInRange(OrderedBag<Product> bag, decimal firstRange, decimal secondRange)
{
List<Product> twenty = new List<Product>();
twenty = bag.FindAll(x => x.Price >= firstRange && x.Price <= secondRange).Take(20).ToList();
foreach (var item in twenty)
{
Console.Write(item + " ");
}
Console.WriteLine();
}
示例5: Main
static void Main(string[] args)
{
OrderedBag<Product> products = new OrderedBag<Product>();
Random randomPrice = new Random();
Stopwatch timer = new Stopwatch();
timer.Start();
for (int i = 0; i < 500000; i++)
{
double price=randomPrice.NextDouble();
products.Add(new Product("someName"+i, price));
}
double min = randomPrice.NextDouble();
double max = randomPrice.NextDouble();
for (int i = 0; i < 10000; i++)
{
products.FindAll(x => x.Price > min && x.Price < max).Take(20);
}
timer.Stop();
Console.WriteLine("Program executed in {0}.", timer.Elapsed);
}