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


C# OrderedMultiDictionary.Add方法代码示例

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


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

示例1: 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

示例2: ScoreboardStringCreationTest

        public void ScoreboardStringCreationTest()
        {
            var statistics = new OrderedMultiDictionary<int, string>(true);
            statistics.Add(5, "Gosho");
            statistics.Add(15, "Pesho");

            var scoreboard = "Scoreboard:" + Environment.NewLine +
                "2. {Gosho} --> 5 moves" + Environment.NewLine +
                "2. {Pesho} --> 15 moves" + Environment.NewLine;

            Assert.AreEqual(scoreboard, ConsoleIOFacade.CreateScoreboardString(statistics));
        }
开发者ID:TishoAngelov,项目名称:TelerikAcademy,代码行数:12,代码来源:ConsoleOutputTests.cs

示例3: 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)));
            }
        }
开发者ID:MarinMarinov,项目名称:Data-structures-and-algorithms,代码行数:34,代码来源:Startup.cs

示例4: Main

        static void Main()
        {
            Article[] articles = {new Article(0999311,"GeorgiIvanovOOD","Gloves",10.56M),
                                     new Article(09945311,"GeorgiIvanovOOD","Hats",8.00M),
                                     new Article(45945311,"ETIliev","Bags",18.00M),
                                     new Article(45947311,"ETIliev","Shoes",18.00M),
                                     new Article(13447311,"ETIliev","Socks",3.99M),
                                     new Article(13412570,"ETDimitrov","BaseballBats",23.99M)};

            OrderedMultiDictionary<decimal, Article> catalog = new OrderedMultiDictionary<decimal, Article>(true);

            foreach (var article in articles)
            {
                catalog.Add(article.Price, article);
            }

            var pricesRange = catalog.FindAll(x => x.Key >= 10 && x.Key <= 20);
            foreach (var item in pricesRange)
            {
                string items = "";
                int count = 0;
                foreach (var article in item.Value)
                {
                    count += 1;
                    items += "article"+count+": "+ article.Title + " " + article.Vedndor + " " + article.Barcode+";\n";
                }

                Console.WriteLine("Price: {0} - articles: {1}",
                    item.Key,items);
            }
        }
开发者ID:Jarolim,项目名称:TelerikAcademy-1,代码行数:31,代码来源:Program.cs

示例5: Main

    static void Main()
    {
        OrderedMultiDictionary<string, Student> students = new OrderedMultiDictionary<string, Student>(true);

        using (StreamReader reader = new StreamReader(@"../../Students.txt"))
        {
            string line = reader.ReadLine();
            while (line != null)
            {
                string[] arguments = ParseInput(line);
                if (arguments.Length == 3)
                {
                    string firstName = arguments[0].Trim();
                    string lastName = arguments[1].Trim();
                    string course = arguments[2].Trim();

                    students.Add(course, new Student(firstName, lastName));
                }

                line = reader.ReadLine();
            }
        }

        foreach (var course in students)
        {
            Console.WriteLine("{0}: {1}", course.Key, string.Join(", ", course.Value));
        }
    }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:28,代码来源:Program.cs

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: Main

        static void Main()
        {

            List<string[]> inputs = ReadData();
            OrderedMultiDictionary<double, Article> byPrice = new OrderedMultiDictionary<double, Article>(true);
            foreach (var input in inputs)
            {
                Article article = new Article(input[0], input[1], input[2], Convert.ToDouble(input[3]));
                byPrice.Add(article.Price, article);
            }

            Console.WriteLine("Print all articles");
            foreach (var item in byPrice)
            {
                Console.WriteLine(item.ToString());
            }

            OrderedMultiDictionary<double, Article>.View priceInRange = GetPriceRange(40, 90, byPrice);
            Console.WriteLine();
            Console.WriteLine("Print articles in range [40, 90]");
            foreach (var item in priceInRange)
            {
                Console.WriteLine(item.ToString());
            }
        }
开发者ID:VesiBaleva,项目名称:TelerikAcademy,代码行数:25,代码来源:SearchArticle.cs

示例11: GenerateProductList

    /// <summary>
    /// Read file and add element to the product list (price with name)
    /// </summary>
    /// <param name="file">File name</param>
    /// <exception cref="ArgumentNullException">
    /// If the file name is null or white space</exception>
    /// <remarks>Use UTF-8 encoding</remarks>
    /// <returns>Created product list</returns>
    public static OrderedMultiDictionary<double, string> GenerateProductList(string file)
    {
        if (string.IsNullOrWhiteSpace(file))
        {
            throw new ArgumentNullException(
                "invalid input! File name cannot be null or white space");
        }

        OrderedMultiDictionary<double, string> productList =
            new OrderedMultiDictionary<double, string>(true);
        StreamReader reader = new StreamReader(file, Encoding.GetEncoding("UTF-8"));
        using (reader)
        {
            string line = reader.ReadLine();
            while (line != null)
            {
                string[] content = line.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                double price = double.Parse(content[1]);
                string name = content[0];
                productList.Add(price, name);
                line = reader.ReadLine();
            }
        }

        return productList;
    }
开发者ID:vasilkrvasilev,项目名称:DataStructuresAlgorithms,代码行数:34,代码来源:ProductList.cs

示例12: 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

示例13: 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

示例14: 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

示例15: Main

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

            var products = new OrderedMultiDictionary<double, string>(true);
            int numberOfLines = int.Parse(Console.ReadLine());
            string line = string.Empty;
            string productName = string.Empty;
            double productPrice = 0;

            for (int i = 0; i < numberOfLines; i++)
            {
                line = Console.ReadLine();

                var parts = line.Split(' ');

                productName = parts[0].Trim();
                productPrice = double.Parse(parts[1].Trim());

                products.Add(productPrice, productName);
            }

            var limits = Console.ReadLine().Split(' ');
            double lowerLimit = double.Parse(limits[0].Trim());
            double upperLimit = double.Parse(limits[1].Trim());
            var productsInRange = products.Range(lowerLimit, true, upperLimit, true);

            foreach (var productInRange in productsInRange)
            {
                Console.WriteLine("{0} {1}", productInRange.Key, productInRange.Value);
            }
        }
开发者ID:ivan4otopa,项目名称:SoftUni,代码行数:32,代码来源:ProductsInPriceRange.cs


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