当前位置: 首页>>代码示例>>C#>>正文


C# OrderedMultiDictionary.Range方法代码示例

本文整理汇总了C#中OrderedMultiDictionary.Range方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedMultiDictionary.Range方法的具体用法?C# OrderedMultiDictionary.Range怎么用?C# OrderedMultiDictionary.Range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OrderedMultiDictionary的用法示例。


在下文中一共展示了OrderedMultiDictionary.Range方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main()
        {
            var products = new OrderedMultiDictionary<decimal, Product>(true);

            Console.Write("Creating and adding products");
            for (int i = 0; i < 1000000; i++)
            {
                products.Add(
                    (i + 1) % 50 + (decimal)i / 100,
                    new Product(
                    "Product #" + (i + 1),
                    ((i + 1) % 50 + (decimal)i / 100),
                    "Vendor#" + i % 50000,
                    null));
                if (i % 1000 == 0)
                {
                    Console.Write(".");
                }
            }

            Console.WriteLine();

            var productsInPricerangeFrom10To11 = products.Range(10M, true, 11M, true);
            var productsInPricerangeFrom15To25 = products.Range(15M, true, 25M, true);
            var productsInPricerangeFrom30To35 = products.Range(30M, true, 35M, true);

            Console.WriteLine("Products with price between 10 and 11: " + productsInPricerangeFrom10To11.Count);
            Console.WriteLine("Products with price between 15 and 25: " + productsInPricerangeFrom15To25.Count);
            Console.WriteLine("Products with price between 30 and 35: " + productsInPricerangeFrom30To35.Count);
        }
开发者ID:dtopalov,项目名称:DSA,代码行数:30,代码来源:CompanyArticlesOperations.cs

示例2: Main

 public static void Main(string[] args)
 {
     var products = new OrderedMultiDictionary<float, string> (true);
     Console.WriteLine("Add 'product price'. 'q' for end. ");
     while(true) {
         var input = Console.ReadLine ();
         if ("q" == input) {
             break;
         }
         var pair = input.Split (' ');
         try {
             products.Add (float.Parse (pair [1]), pair [0]);
         } catch (FormatException e) {
             Console.WriteLine (e.Message);
         }
     }
     Console.WriteLine("Add range 'price1 price2'. 'q' for end. ");
     while (true) {
         var input = Console.ReadLine ();
         if ("q" == input) {
             break;
         }
         var range = input.Split (' ');
         try {
             Console.WriteLine(products.Range (float.Parse(range [0]), true, float.Parse(range [1]), true));
         } catch (FormatException e) {
             Console.WriteLine (e.Message);
         }
     }
 }
开发者ID:psha-,项目名称:softuni-datastruct,代码行数:30,代码来源:Program.cs

示例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);
            }
        }
开发者ID:HansS,项目名称:TelerikAcademy-homework,代码行数:31,代码来源:Program.cs

示例4: Main

        public static void Main(string[] args)
        {
            OrderedMultiDictionary<double, Article> articles = new OrderedMultiDictionary<double, Article>(true);
            Random randomNumberGenerator = new Random();
            double randomNumber;
            for (int i = 0; i < 2000000; i++)
            {
                randomNumber = randomNumberGenerator.NextDouble() * MaxValue;
                Article article = new Article("barcode" + i, "vendor" + i, "article" + i, randomNumber);
                articles.Add(article.Price, article);
            }

            Console.Write("from = ");
            double from = double.Parse(Console.ReadLine());
            Console.Write("to = ");
            double to = double.Parse(Console.ReadLine());
            var articlesInRange = articles.Range(from, true, to, true);
            foreach (var pair in articlesInRange)
            {
                foreach (var article in pair.Value)
                {
                    Console.WriteLine("{0} => {1}", Math.Round(article.Price, 2), article);
                }
            }
        }
开发者ID:Elinos,项目名称:TelerikAcademy,代码行数:25,代码来源:ElementsInRange.cs

示例5: PrintAllArticlesFromGivenRange

 private static void PrintAllArticlesFromGivenRange(OrderedMultiDictionary<int, Article> articles, int from, int to)
 {
     foreach (var article in articles.Range(from, true, to, true))
     {
         Console.WriteLine(article.Value.ToString());
     }
 }
开发者ID:RamiAmaire,项目名称:TelerikAcademy,代码行数:7,代码来源:Demo.cs

示例6: Main

    /* 2. A large trade company has millions of articles, each described
       by barcode, vendor, title and price. Implement a data structure to
       store them that allows fast retrieval of all articles in given price
       range [x...y].

       Hint: use OrderedMultiDictionary<K,T> from Wintellect's Power
       Collections for .NET.
     * */
    static void Main(string[] args)
    {
        // What's there to "implement"?
        // That's exactly what OrderedMultiDictionary was made for.

        // input generator in bin\debug\generator.cs

        var products = new OrderedMultiDictionary<decimal, string>(true);

        foreach (var line in File.ReadLines("products.txt").Skip(1))
        {
            var split = line.Split('|');
            products.Add(decimal.Parse(split[0]), split[1]);
        }

        foreach (var line in File.ReadLines("commands.txt"))
        {
            Console.WriteLine("Command: " + line);
            var split = line.Split('|');

            var first = decimal.Parse(split[0]);
            var second = decimal.Parse(split[1]);

            var matching = products.Range(Math.Min(first, second), true,
                                          Math.Max(first, second), true);

            Console.WriteLine(string.Join(", ", matching));
            Console.WriteLine();
            Console.WriteLine("Press Ctrl+C to quit, or any other key to continue...");
            Console.ReadLine();
        }
    }
开发者ID:staafl,项目名称:ta-hw-dsa,代码行数:40,代码来源:program.cs

示例7: Main

        public static void Main()
        {
            OrderedMultiDictionary<double, Article> articles = new OrderedMultiDictionary<double, Article>(true);

            int range = 10000;
            for (int i = 0; i < range; i++)
            {
                var article = new Article("barcode" + i, "vendor" + i, "title" + i, i);
                articles.Add(article.Price, article);
            }

            int from = 5000;
            int to = 5040;

            //Make some duplications
            for (int i = from; i < to - 30; i++)
            {
                var article = new Article("newBarcode" + i, "newVendor" + i, "newTitle" + i, i);
                articles.Add(article.Price, article);
            }

            var articlesInGivenRange = articles.Range(from, true, to, true);
            foreach (var article in articlesInGivenRange)
            {
                foreach (var item in article.Value)
                {
                    Console.WriteLine("Title: {0}, Vendor: {1}, Barcode: {2}, Price: {3}",
                    item.Title, item.Vendor, item.Barcode, item.Price);
                }
                Console.WriteLine();
            }
        }
开发者ID:Nottyy,项目名称:TelerikAcademy,代码行数:32,代码来源:TestEntry.cs

示例8: Main

    static void Main()
    {
        StreamReader fileName = new StreamReader("../../products.txt");

        OrderedMultiDictionary<decimal, string> productsByPrice = new OrderedMultiDictionary<decimal, string>(true);

        using (fileName)
        {
            string line;

            while ((line = fileName.ReadLine()) != null)
            {
                var tokens = line.Split(';');
                decimal price = decimal.Parse(tokens[0]);
                string product = tokens[1];

                productsByPrice.Add(price, product);
            }
        }

        Console.WriteLine("Search products in price range: ");
        Console.Write("From price:");
        decimal fromPrice = decimal.Parse(Console.ReadLine());
        Console.Write("To price: ");
        decimal toPrice = decimal.Parse(Console.ReadLine());

        var productsInPriceRange = productsByPrice.Range(fromPrice, true, toPrice, true);

        Console.Write("Number of products to be printed: ");
        int numberOfProductsToPrint = int.Parse(Console.ReadLine());

        PrintGivenNumberOfProducts(numberOfProductsToPrint, productsInPriceRange);
    }
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:33,代码来源:ProductsInPriceRange.cs

示例9: Main

    static void Main()
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

        var events = new OrderedMultiDictionary<DateTime, string>(true);
        int eventsCount = int.Parse(Console.ReadLine());
        for (int i = 0; i < eventsCount; i++)
        {
            string[] eventParams = Console.ReadLine().Split('|');
            string eventName = eventParams[0].Trim();
            var eventTime = DateTime.Parse(eventParams[1].Trim());
            events.Add(eventTime, eventName);
        }

        int rangesCount = int.Parse(Console.ReadLine());
        for (int i = 0; i < rangesCount; i++)
        {
            string[] timeParams = Console.ReadLine().Split('|');
            var startTime = DateTime.Parse(timeParams[0].Trim());
            var endTime = DateTime.Parse(timeParams[1].Trim());

            var filteredEvents = events.Range(startTime, true, endTime, true);
            Console.WriteLine(filteredEvents.Values.Count);
            foreach (var timeEventsPair in filteredEvents)
            {
                foreach (string eventName in timeEventsPair.Value)
                {
                    Console.WriteLine("{0} | {1}", eventName, timeEventsPair.Key);
                }
            }
        }
    }
开发者ID:vangelov-i,项目名称:Fundamentals,代码行数:32,代码来源:EventsInGivenDateRange.cs

示例10: Main

        static void Main(string[] args)
        {
            OrderedMultiDictionary<decimal, Article> articles = 
                new OrderedMultiDictionary<decimal, Article>(true);

            articles.Add(12.43m, new Article("Choco", "123124234", "Milka", 12.43m));
            articles.Add(14.43m, new Article("Natural", "123124234", "Milka", 14.43m));
            articles.Add(15.43m, new Article("Raffy", "123124234", "Milka", 15.43m));
            articles.Add(17.43m, new Article("Milk", "123124234", "Milka", 17.43m));
            articles.Add(18.43m, new Article("Sugar", "123124234", "Milka", 18.43m));
            articles.Add(19.43m, new Article("Bread", "123124234", "Milka", 19.43m));
            articles.Add(20.43m, new Article("Susam", "123124234", "Milka", 20.43m));
            articles.Add(23.43m, new Article("Paper", "123124234", "Milka", 23.43m));
            articles.Add(25.43m, new Article("Grape", "123124234", "Milka", 25.43m));
            articles.Add(54.43m, new Article("Banana", "123124234", "Milka", 54.43m));
            articles.Add(43.43m, new Article("Orange", "123124234", "Milka", 43.43m));
            articles.Add(32.43m, new Article("Melon", "123124234", "Milka", 32.43m));
            articles.Add(24.43m, new Article("WaterMelon", "123124234", "Milka", 24.43m));
            articles.Add(76.43m, new Article("Junk", "123124234", "Milka", 76.43m));

            var rangeArticles = articles.Range(20m, true, 35m, true);
            foreach (var article in rangeArticles)
            {
                foreach (var item in article.Value)
                {
                    Console.WriteLine(item);
                }
            }
        }
开发者ID:VyaraGGeorgieva,项目名称:TelerikAcademy,代码行数:29,代码来源:Program.cs

示例11: 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);
            }
        }
开发者ID:alex687,项目名称:SoftUni-Homeworks,代码行数:32,代码来源:Program.cs

示例12: Main

        public static void Main()
        {
            var productByPrice = new OrderedMultiDictionary<double, string>(true);
            int linesCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < linesCount; i++)
            {
                string input = Console.ReadLine();
                string[] inputArgs = input.Split();
                double price = double.Parse(inputArgs[1]);
                string product = inputArgs[0];

                productByPrice.Add(price, product);
            }

            double[] range = Console.ReadLine().Split().Select(double.Parse).ToArray();

            var productsInRange = productByPrice.Range(range[0], true, range[1], true);

            int count = 0;
            foreach (var product in productsInRange)
            {
                if (count == 20)
                {
                    break;
                }

                Console.WriteLine(product.Key + " " + product.Value.First());
                count++;
            }
        }
开发者ID:pavelilchev,项目名称:HomeWorks,代码行数:31,代码来源:ProductsInPriceRange.cs

示例13: Main

    static void Main()
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

        var events = new OrderedMultiDictionary<DateTime, string>(true);
        int eventsCount = int.Parse(Console.ReadLine());
        for (int i = 0; i < eventsCount; i++)
        {
            string eventEntry = Console.ReadLine();
            var eventTokens = eventEntry.Split('|');
            string eventName = eventTokens[0].Trim();
            DateTime eventDate = DateTime.Parse(eventTokens[1].Trim());
            events.Add(eventDate, eventName);
        }

        int seratchCount = int.Parse(Console.ReadLine());
        for (int i = 0; i < seratchCount; i++)
        {
            string dateEntry = Console.ReadLine();
            var dateTokens = dateEntry.Split('|');
            DateTime startDate = DateTime.Parse(dateTokens[0].Trim());
            DateTime endDate = DateTime.Parse(dateTokens[1].Trim());
            var eventsInRange = events.Range(startDate, true, endDate, true);

            Console.WriteLine("\n\rResult:" + eventsInRange);
            PrintEvents(eventsInRange);
            Console.WriteLine();
        }
    }
开发者ID:milen-vm,项目名称:Data-Structures,代码行数:29,代码来源:EventsInGivenDateRange.cs

示例14: Main

        public static void Main(string[] args)
        {
            var productsAndPrices = new OrderedMultiDictionary<int, string>(true);
            var rng = new Random();
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            for (int i = 0; i < 500000; i++)
            {
                var product = GenerateProduct(rng, i);
                var tokens = product.Split('|');
                var name = tokens[0].Trim();
                var price = int.Parse(tokens[1].Trim());
                productsAndPrices.Add(price, name);
            }

            Console.WriteLine("Seed time: " + stopwatch.Elapsed);
            stopwatch.Restart();
            Console.WriteLine("Query Start");
            var printed = new Set<int>();
            for (int i = 0; i < 10000; i++)
            {
                var startPrice = rng.Next(0, 100001);
                var endPrice = rng.Next(startPrice, 100001);
                var productsInRange = productsAndPrices.Range(startPrice, true, endPrice, true).Take(20);
                var count = productsInRange.Count();
                if (!printed.Contains(count))
                {
                    Console.WriteLine("{0} to {1} -> {2}", startPrice, endPrice, count);
                    printed.Add(count);
                }
            }

            Console.WriteLine("Query time: " + stopwatch.Elapsed);
            Console.WriteLine("All Done");
        }
开发者ID:peterkirilov,项目名称:SoftUni-1,代码行数:35,代码来源:ProductsInPriceRange.cs

示例15: Main

        public static void Main()
        {
            Console.WriteLine("Adding products");

            var products = new OrderedMultiDictionary<decimal, string>(true);

            for (int i = 0; i < 500000; i++)
            {
                var currentPrice = (i * Math.Abs(Math.Sin(i)));
                products.Add((decimal)currentPrice, "Product " + i);

                if (i % 5000 == 0)
                {
                    Console.Write(".");
                }
            }

            Console.WriteLine();

            decimal minPrice = 100000M;
            decimal maxPrice = 110000M;

            Console.WriteLine("Top 20 product in price range [{0}, {1}]", minPrice, maxPrice);

            var result = products.Range(minPrice, true, maxPrice, true).ToList().Take(20);

            foreach (var product in result)
            {
                Console.WriteLine("Name: {0}, Price: {1}", product.Value, product.Key);
            }
        }
开发者ID:p0150n,项目名称:TelerikAcademy,代码行数:31,代码来源:Startup.cs


注:本文中的OrderedMultiDictionary.Range方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。