本文整理汇总了C#中OrderedMultiDictionary.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedMultiDictionary.ContainsKey方法的具体用法?C# OrderedMultiDictionary.ContainsKey怎么用?C# OrderedMultiDictionary.ContainsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderedMultiDictionary
的用法示例。
在下文中一共展示了OrderedMultiDictionary.ContainsKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
int productsNumber = int.Parse(Console.ReadLine());
var productsOrderedByPrice = new OrderedMultiDictionary<float, string>(true);
for (int i = 0; i < productsNumber; i++)
{
string name = Console.ReadLine();
float price = float.Parse(Console.ReadLine());
if (!productsOrderedByPrice.ContainsKey(price))
{
productsOrderedByPrice.Add(price, name);
}
else
{
productsOrderedByPrice[price].Add(name);
}
}
var startPrice = float.Parse(Console.ReadLine());
var endPrice = float.Parse(Console.ReadLine());
var range = productsOrderedByPrice.Range(startPrice, true, endPrice, true).Take(20);
foreach (var keyValuePair in range)
{
Console.WriteLine("{0} -> {1}", keyValuePair.Key, keyValuePair.Value);
}
}
示例2: Main
public static void Main()
{
var reader = new StreamReader("../../Students.txt");
var dictionary = new OrderedMultiDictionary<string, Student>(true);
string line = reader.ReadLine();
while (line != null)
{
string[] splitedLine = line.Split(new char[]{'|'}, StringSplitOptions.RemoveEmptyEntries).Select(word => word.Trim()).ToArray();
Student student = new Student(splitedLine[0], splitedLine[1]);
if(!dictionary.ContainsKey(splitedLine[2]))
{
dictionary.Add(splitedLine[2], student);
}
else
{
dictionary[splitedLine[2]].Add(student);
}
line = reader.ReadLine();
}
foreach (var pair in dictionary)
{
Console.Write(pair.Key + " : ");
var orderedList = pair.Value.OrderBy(v => v.LastName).ThenBy(v => v.FirstName).ToList();
Console.WriteLine(string.Join(", ", orderedList.Select(s => s.FirstName + " " + s.LastName)));
}
}
示例3: Main
public static void Main(string[] args)
{
Random randGen = new Random();
OrderedMultiDictionary<Article, int> articles = new OrderedMultiDictionary<Article, int>(false);
for (int i = 0; i < 100; i++)
{
Article myArticle = new Article(randGen.Next(10000, 99999), "Vendor" + i, "Title" + i, randGen.Next(1000, 9999));
if (!articles.ContainsKey(myArticle))
{
articles.Add(myArticle, 1);
}
}
Console.WriteLine("Enter bottom price:");
int startPrice = int.Parse(Console.ReadLine());
Console.WriteLine("Enter top price:");
int endPrice = int.Parse(Console.ReadLine());
OrderedMultiDictionary<Article, int>.View neededArticles = articles.Range(
new Article(0, string.Empty, string.Empty, 2000),
true,
new Article(0, string.Empty, string.Empty, 4000),
true);
foreach (var item in neededArticles)
{
Console.WriteLine(item.Key);
}
}
示例4: Main
static void Main()
{
OrderedMultiDictionary<double, Article> articles = new OrderedMultiDictionary<double, Article>(true);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
string line;
using (StreamReader reader = new StreamReader(@"..\..\data1500000.csv"))
{
line = reader.ReadLine();
while ((line = reader.ReadLine()) != null)
{
string[] content = line.Split(new char[] { ',', '"' }, StringSplitOptions.RemoveEmptyEntries);
Article article = new Article(content[0], content[1], content[2], double.Parse(content[3]));
if (articles.ContainsKey(article.Price))
{
articles[article.Price].Add(article);
}
else
{
articles.Add(article.Price, article);
}
}
}
stopwatch.Stop();
Console.WriteLine("Create and add 15k Articles: {0}", stopwatch.Elapsed);
stopwatch.Reset();
stopwatch.Restart();
var result = articles.Range(14556.0, true, 4665542.0, true);
stopwatch.Stop();
Console.WriteLine("Search: {0}", stopwatch.Elapsed);
Console.WriteLine(result.Count);
//To test with 1 500 000 mil Articles download 100mb file:
//http://www.4shared.com/rar/kBeJdHzA/data1500000.html
//http://www.filedropper.com/data1500000
//Create and add 1 500 000 mil Articles: 00:00:19.8488240
//Search: 00:00:00.0015390
//1394252
//Press any key to continue . . .
}
示例5: Main
static void Main()
{
OrderedMultiDictionary<double, Article> articles = new OrderedMultiDictionary<double, Article>(true);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
string line;
using (StreamReader reader = new StreamReader(@".../../data.csv"))
{
line = reader.ReadLine();
while ((line = reader.ReadLine()) != null)
{
string[] content = line.Split(new char[] {',','"'}, StringSplitOptions.RemoveEmptyEntries);
string barcode = content[0];
string vendor = content[1];
string title = content[2];
double price = Double.Parse(content[3]);
Article currentArticle = new Article(barcode, vendor, title, price);
if (articles.ContainsKey(currentArticle.Price))
{
articles[currentArticle.Price].Add(currentArticle);
}
else
{
articles.Add(currentArticle.Price, currentArticle);
}
}
}
stopwatch.Stop();
Console.WriteLine("Create and Add 15 000 Articles: {0}", stopwatch.Elapsed);
stopwatch.Reset();
stopwatch.Restart();
var result = articles.Range(1234.0, true, 13456.0, true);
stopwatch.Stop();
Console.WriteLine("Search: {0}", stopwatch.Elapsed);
Console.WriteLine(result.Count);
}