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


C# OrderedDictionary.ContainsKey方法代码示例

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


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

示例1: RemoveNumbersThatOccurOddNumbers

        public static string RemoveNumbersThatOccurOddNumbers(int[] input)
        {
            HashSet<int> whiteList = new HashSet<int>();
            var uniqueValuesInList = new OrderedDictionary<int, int>();
            foreach (var item in input)
            {
                if (uniqueValuesInList.ContainsKey(item))
                {
                    uniqueValuesInList[item]++;
                }
                else
                {
                    uniqueValuesInList.Add(item, 1);
                }
            }

            string result = null;
            foreach (var item in uniqueValuesInList)
            {
                if (item.Value >= (uniqueValuesInList.Count / 2) + 1)
                {
                    result = string.Format("Majorant number is {0}.", item.Key);
                }
            }

            if (result == null)
            {
                result = "Does not exist majorant number.";
            }

            return result;
        }
开发者ID:quela,项目名称:myprojects,代码行数:32,代码来源:FindMajorant.cs

示例2: SaveInput

        private static OrderedDictionary<string, SortedSet<Student>> SaveInput()
        {
            OrderedDictionary<string, SortedSet<Student>> input = new OrderedDictionary<string, SortedSet<Student>>();
            // just link the txt file from the project ->
            string path = @"C:\users\student\documents\visual studio 2012\Projects\[DSA] Data-Structures-Efficiency\1. PrintingOrderedStudents\students.txt";
            StreamReader reader = new StreamReader(path);

            using (reader)
            {
                string line = reader.ReadLine();
                while (line != null && line != string.Empty)
                {
                    string[] attribs = ParseLine(line);
                    Student newStud =  new Student(attribs[0], attribs[1]);
                    if (input.ContainsKey(attribs[2]))
                    {
                        input[attribs[2]].Add(newStud);
                    }
                    else
                    {
                        input[attribs[2]] = new SortedSet<Student>();
                        input[attribs[2]].Add(newStud);
                    }

                    line = reader.ReadLine();
                }
            }

            return input;
        }
开发者ID:RamiAmaire,项目名称:TelerikAcademy,代码行数:30,代码来源:Demo.cs

示例3: Main

        static void Main(string[] args)
        {
            OrderedDictionary<string, SortedSet<Person>> coursesAndStudents = new OrderedDictionary<string, SortedSet<Person>>();

            while (true)
            {
                string[] input = Console.ReadLine().Split(new[] { ' ', '|' }, StringSplitOptions.RemoveEmptyEntries);
                string course = input[2].Trim();
                string firstName = input[0].Trim();
                string lastName = input[1].Trim();

                if (coursesAndStudents.ContainsKey(course))
                {
                    coursesAndStudents[course].Add(new Person(firstName, lastName));
                }
                else
                {
                    SortedSet<Person> set = new SortedSet<Person>();
                    set.Add(new Person(firstName, lastName));
                    coursesAndStudents.Add(course, set);
                }

                Output(coursesAndStudents);
            }
        }
开发者ID:simooo93,项目名称:SoftUni-Homeworks,代码行数:25,代码来源:Program.cs

示例4: Tokenize

 public IDictionary<string, double> Tokenize(string line)
 {
     OrderedDictionary<string, double> res = new OrderedDictionary<string, double>();
     foreach (string elt in line.Split(' '))
         if (res.ContainsKey(elt))
             res[elt]++;
         else
             res.Add(elt, 1);
     return res;
 }
开发者ID:turboNinja2,项目名称:Rob-The-Robot,代码行数:10,代码来源:OrderedCounts.cs

示例5: Clear

        public void Clear()
        {
            var dict = new OrderedDictionary<int, int> { { 1, 2 }, { 2, 3 }, { 3, 4 }, { 4, 5 } };

            dict.Clear();

            Assert.AreEqual(0, dict.Count);
            Assert.AreEqual(0, dict.Values.Count);
            Assert.IsFalse(dict.ContainsKey(1));
            Assert.IsFalse(dict.ContainsValue(2));
        }
开发者ID:mono,项目名称:rocks,代码行数:11,代码来源:OrderedDictionaryTest.cs

示例6: Main

    static void Main(string[] args)
    {
        const string fileName = "students.txt";

        string input = Console.ReadLine();

        using (StreamWriter newWriter = File.AppendText(fileName))
        {
            while (input != "end")
            {
                newWriter.WriteLine(input);
                input = Console.ReadLine();
            }
        }

        var dataStorage = new OrderedDictionary<string, OrderedDictionary<string, Person>>();

        using (var streamReader = new StreamReader(fileName))
        {
            string currentLine;

            while ((currentLine = streamReader.ReadLine()) != null)
            {
                string[] parameters = currentLine.Split(new char[] { ' ', '|' }, StringSplitOptions.RemoveEmptyEntries);

                string firstName = parameters[0];
                string lastName = parameters[1];
                string course = parameters[2];

                if (!dataStorage.ContainsKey(course))
                {
                    dataStorage.Add(course, new OrderedDictionary<string, Person>());
                }

                if (!dataStorage[course].ContainsKey(lastName))
                {
                    dataStorage[course].Add(lastName, new Person(firstName, lastName));
                }
            }
        }

        foreach (var course in dataStorage)
        {
            Console.Write($"{course.Key} -> ");
            string peopleInCourse = "";
            foreach (var person in course.Value)
            {
                peopleInCourse += ", " + person.Value.ToString();
            }

            peopleInCourse = peopleInCourse.Remove(0, 2);
            Console.WriteLine(peopleInCourse);
        }
    }
开发者ID:MishoMihaylov,项目名称:Homeworks,代码行数:54,代码来源:Demo.cs

示例7: FindOccursNumbrersInArray

        public static OrderedDictionary<int, int> FindOccursNumbrersInArray(int[] input)
        {
            var uniqueValuesInList = new OrderedDictionary<int, int>();
            foreach (var item in input)
            {
                if (uniqueValuesInList.ContainsKey(item))
                {
                    uniqueValuesInList[item]++;
                }
                else
                {
                    uniqueValuesInList.Add(item, 1);
                }
            }

            return uniqueValuesInList;
        }
开发者ID:quela,项目名称:myprojects,代码行数:17,代码来源:OccursNumbrersInArray.cs

示例8: Main

    /* Task 2:
     * Write a program to read a large collection of products (name + price) I love 
     * and efficiently find the first 20 products in the price range [a…b]. Test for 
     * 500 000 products and 10 000 price searches.
     * Hint: you may use OrderedBag<T> and sub-ranges.
     */

    static void Main(string[] args)
    {
        Random randomGenerator = new Random();
        Stopwatch stopWatch = new Stopwatch();

        string[] product = { "bread", "butter", "meat", "eggs", "flower", "oil", "soda", "candy" };
        var productLenght = product.Length;
        var orderedDictionary = new OrderedDictionary<int, string>();

        stopWatch.Start();
        while (orderedDictionary.Count < 500000)
        {
            var key = randomGenerator.Next(1, 1000000);
            var value = product[randomGenerator.Next(0, productLenght)];
            if (!orderedDictionary.ContainsKey(key))
            {
                orderedDictionary.Add(key, value);
            }
        }

        stopWatch.Stop();

        Console.WriteLine("Time for creating the elements is: {0}", stopWatch.Elapsed);

        stopWatch.Reset();

        stopWatch.Start();
        for (int i = 0; i < 10000; i++)
        {
            var min = randomGenerator.Next(0, 500000);
            var max = randomGenerator.Next(500000, 1000000);
            var products = orderedDictionary.Range(min, true, max, true);
        }
        stopWatch.Stop();

        Console.WriteLine("Time for performing 10k range searches: {0}", stopWatch.Elapsed);

        var range = orderedDictionary.Range(1000, true, 100000, true);

        for (int i = 0; i < 20; i++)
        {
            Console.WriteLine(range.ElementAt(i));
        }
    }
开发者ID:aleks-todorov,项目名称:HomeWorks,代码行数:51,代码来源:FindProduct.cs

示例9: VarsNeededForDecode

 public void VarsNeededForDecode(PEREffectiveConstraint cns, int arrayDepth, OrderedDictionary<string, CLocalVariable> existingVars)
 {
     if (!existingVars.ContainsKey("nChoiceIndex"))
         existingVars.Add("nChoiceIndex", new CLocalVariable("nChoiceIndex", "asn1SccSint", 0, "0"));
     foreach (ChoiceChild ch in m_children.Values)
     {
         ((ISCCType)ch.m_type).VarsNeededForDecode(ch.m_type.PEREffectiveConstraint, arrayDepth, existingVars);
     }
 }
开发者ID:kia92798,项目名称:tinyasn1,代码行数:9,代码来源:SCCChoiceType.cs

示例10: InternalGetSamplesByGenome

 private static OrderedDictionary<string, List<Sample>> InternalGetSamplesByGenome(List<Sample> samples)
 {
     var samplesByGenome = new OrderedDictionary<string, List<Sample>>(StringComparer.OrdinalIgnoreCase);
     foreach (Sample sample in samples)
     {
         if (!samplesByGenome.ContainsKey(sample.GenomePath))
             samplesByGenome[sample.GenomePath] = new List<Sample>();
         samplesByGenome[sample.GenomePath].Add(sample);
     }
     return samplesByGenome;
 }
开发者ID:abladon,项目名称:canvas,代码行数:11,代码来源:SampleSheet.cs

示例11: VarsNeededForDecode

 public void VarsNeededForDecode(PEREffectiveConstraint cns, int arrayDepth, OrderedDictionary<string, CLocalVariable> existingVars)
 {
     PERIntegerEffectiveConstraint cn = cns as PERIntegerEffectiveConstraint;
     if (cns != null && cn.Extensible)
     {
         if (!existingVars.ContainsKey("extBit"))
         {
             existingVars.Add("extBit", new CLocalVariable("extBit", "flag", 0, "FALSE"));
         }
     }
 }
开发者ID:kia92798,项目名称:tinyasn1,代码行数:11,代码来源:SCCSingleTypes.cs

示例12: VarsNeededForEncode

 public static void VarsNeededForEncode(SizeableType pThis, PEREffectiveConstraint cns, int arrayDepth, OrderedDictionary<string, CLocalVariable> existingVars)
 {
     string var = "i" + arrayDepth.ToString();
     if (!existingVars.ContainsKey(var))
     {
         existingVars.Add(var, new CLocalVariable(var, "int", 0, "0"));
     }
     if (pThis.maxItems(cns) > 0x10000)
     {
         var = "nCount" + arrayDepth.ToString();
         if (!existingVars.ContainsKey(var))
             existingVars.Add(var, new CLocalVariable(var, "asn1SccSint", 0, "0"));
         var = "curBlockSize" + arrayDepth.ToString();
         if (!existingVars.ContainsKey(var))
             existingVars.Add(var, new CLocalVariable(var, "asn1SccSint", 0, "0"));
         var = "curItem" + arrayDepth.ToString();
         if (!existingVars.ContainsKey(var))
             existingVars.Add(var, new CLocalVariable(var, "asn1SccSint", 0, "0"));
     }
 }
开发者ID:kia92798,项目名称:tinyasn1,代码行数:20,代码来源:SCCArray.cs

示例13: VarsNeededForDecode

        public static void VarsNeededForDecode(SequenceOrSetType pThis, PEREffectiveConstraint cns, int arrayDepth, OrderedDictionary<string, CLocalVariable> existingVars)
        {
            int nBitMaskLength = (int)Math.Ceiling(pThis.GetNumberOfOptionalOrDefaultFields() / 8.0);
            if (nBitMaskLength > 0)
            {
                if (!existingVars.ContainsKey("bitMask"))
                    existingVars.Add("bitMask", new CLocalVariable("bitMask", "byte", nBitMaskLength, ""));
                else
                {
                    CLocalVariable lv = existingVars["bitMask"];
                    if (lv.arrayLen < nBitMaskLength)
                        lv.arrayLen = nBitMaskLength;
                }
            }

            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                ((ISCCType)ch.m_type).VarsNeededForDecode(ch.m_type.PEREffectiveConstraint, arrayDepth, existingVars);
            }
        }
开发者ID:kia92798,项目名称:tinyasn1,代码行数:20,代码来源:SequenceOrSetType.cs

示例14: GetSetWithComponent

        public override OrderedDictionary<string, ISet> GetSetWithComponent()
        {
            OrderedDictionary<string, ISet> ret = new OrderedDictionary<string, ISet>();
            Asn1Type curType = this;
            while (curType != null)
            {
                foreach (IConstraint con in curType.m_constraints)
                {
                    List<KeyValuePair<string, ISet>> list = con.GetSetWithComponent();
                    foreach (KeyValuePair<string, ISet> p in list)
                    {
                        if (!ret.ContainsKey(p.Key))
                            ret.Add(p.Key, p.Value);
                        else
                            ret[p.Key] = ret[p.Key].Intersect(p.Value);
                    }
                }

                curType = curType.ParentType;
            }
            return ret;
        }
开发者ID:kia92798,项目名称:tinyasn1,代码行数:22,代码来源:ReferenceType.cs

示例15: ContainsKey_KeyNull

 public void ContainsKey_KeyNull()
 {
     var dict = new OrderedDictionary<string, int>();
     dict.ContainsKey (null);
 }
开发者ID:mono,项目名称:rocks,代码行数:5,代码来源:OrderedDictionaryTest.cs


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