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


C# Dictionary.ContainsValue方法代码示例

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


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

示例1: collections_example

        public collections_example()
        {
            //rule of thumb: generics exist and are a wonderful thing.

            //Lists
            List<string> sList = new List<string>();
            var namesList = new List<string>();//this is implying that var is a List<string>. It shortens variable declarations. This cannot be used as a return type. Variables only.

            sList.Add("James");//this is rather time consuming and not helpful. You are usually adding this from a db or data file.

            //you can add arrays to collections.
            string[] names = new string[]{
                "James",
                "John",
                "Jennifer",
                "Jackie",
                "Jake",
                "Jeremy"
            };
            namesList.AddRange(names);//this adds all the names in an array

            Console.WriteLine("The number of items in namesList is "+namesList.Count); //checks how many values are in the collection.

            bool james = namesList.Contains("James");//would return true.
            bool katie = namesList.Contains("Katie");// returns false

            Console.WriteLine("Does it contain James? {0}\nDoes it contain Katie? {1}\n", james, katie);

            var newList = namesList.FindAll((s) => s[1] == 'a');//lamba expressions, quickest way to write a predicate. More on this in future lessons.
            //copies the name whose second letter contains an a
            Console.WriteLine(newList.ToArray());//prints the name of the array, not the names IN the array.

            foreach (var name in newList)
            {
                Console.WriteLine(name);
            }

            //there's all sorts of stuff you can do to these. Remove, add, skip, sort, foreach, and far more. Use them on an as-needed basis.

            namesList.Clear();//clears everything so it is back at 0. Good for "cleaning the slate". YOU CANNOT GET THEM BACK!

            //Dictionaries
            Dictionary<int, string> dict = new Dictionary<int, string>();//could use var as well.
            dict.Add(0, "Jeremy");//keys must be unique. Int is the key.
            dict.Add(1, "Jake");// this changes the key value.
            dict.Add(2, "Hanna");

            string value = dict[0];//Jeremy
            Console.WriteLine("The value of value is: " + value);

            dict.ContainsValue("0");//returns true
            dict.ContainsValue("9");//returns false

            dict.Remove(1);//usually use a foreach loop to remove all values.

            foreach (var key in dict)
            {
                Console.WriteLine(key.Key + " = " + key.Value);
            }
        }
开发者ID:jcoddaire,项目名称:C-Sharp-Code,代码行数:60,代码来源:collections_example.cs

示例2: Catagorize

        public override HandRanking Catagorize(Hand hand)
        {
            Dictionary<Value, int> seen = new Dictionary<Value, int>();

            foreach (Card c in hand.Cards)
            {
                if (seen.ContainsKey(c.Value))
                {
                    seen[c.Value]++;
                }
                else
                {
                    seen[c.Value] = 1;
                }
            }

            if (seen.Count == 2)
            {
                if(seen.ContainsValue(3) && seen.ContainsValue(2))
                {
                    return HandRanking.FullHouse;
                }
            }

            return Next.Catagorize(hand);
        }
开发者ID:skalinets,项目名称:DesignPatterns,代码行数:26,代码来源:Catagorizers.cs

示例3: IsFourOfAKind

        public bool IsFourOfAKind(IHand hand)
        {
            if (!this.IsValidHand(hand))
            {
                return false;
            }

            Dictionary<CardFace, int> faces = new Dictionary<CardFace, int>();
            for (var i = 0; i < NumberOfCardsInHand; i++)
            {
                if (!faces.ContainsKey(hand.Cards[i].Face))
                {
                    faces.Add(hand.Cards[i].Face, 1);
                }
                else
                {
                    faces[hand.Cards[i].Face] = faces[hand.Cards[i].Face] + 1;
                }
            }

            if (faces.Count == 2 && faces.ContainsValue(4) && faces.ContainsValue(1) && faces.Count == 2)

            {
                return true;
            }
            else
            {
                return false;
            }
        }
开发者ID:emilti,项目名称:Telerik-Academy-My-Courses,代码行数:30,代码来源:PokerHandsChecker.cs

示例4: TheIdMapWillContainAMapOfAllChildren

        public void TheIdMapWillContainAMapOfAllChildren()
        {
            TestHierarchy h = new TestHierarchy();
            Dictionary<int, UnityObject> ids = new Dictionary<int, UnityObject>();

            h.root.SetNewId(ids);
            Assert.That(ids.ContainsValue(h.root), Is.True);
            Assert.That(ids.ContainsValue(h.child), Is.True);
            Assert.That(ids.ContainsValue(h.childOfChild), Is.True);
        }
开发者ID:Joelone,项目名称:FFWD,代码行数:10,代码来源:WhenSettingNewIds.cs

示例5: TheIdMapWillContainTheObjectAndItsOriginalId

        public void TheIdMapWillContainTheObjectAndItsOriginalId()
        {
            Dictionary<int, UnityObject> ids = new Dictionary<int, UnityObject>();
            GameObject go = new GameObject();

            go.SetNewId(ids);

            Assert.That(ids.Count, Is.EqualTo(2));
            Assert.That(ids.ContainsValue(go), Is.True);
            Assert.That(ids.ContainsValue(go.transform), Is.True);
        }
开发者ID:Joelone,项目名称:FFWD,代码行数:11,代码来源:WhenSettingNewIds.cs

示例6: Main

        static void Main(string[] args)
        {
            //Get the string from the application config
            var initialWord = ConfigurationManager.AppSettings["initialString"];

            initialWord = initialWord.ToLower();
            var initialWordFrequence=Class1.getFrequenceVector(initialWord);

            //The words from the file are kept in a dictionary, together with their frequence vector
            var wordsFromFileDict = new Dictionary<string, Dictionary<char, int>>();

            //The result strings are kept in a dictionary
            var resultDict = new Dictionary<string, string>();

            var reader = new StreamReader("wordList.txt");
            var line = "";
            while (line != null)
            {
                line = reader.ReadLine();

                if (line == null)
                    break;
                line = line.ToLower();
                if(!wordsFromFileDict.ContainsKey(line))
                    wordsFromFileDict.Add(line, Class1.getFrequenceVector(line));
            }

            foreach (var x in wordsFromFileDict)
            {

                //Console.WriteLine(x.ToLower());
                foreach (var y in wordsFromFileDict)
                {
                    initialWordFrequence = Class1.getFrequenceVector(initialWord);
                    if (Class1.canBeAnagrams(x.Value, y.Value, initialWordFrequence))

                        if (Class1.areAnagrams(x.Value, y.Value, initialWordFrequence))
                            //Doesn't add duplicates in the result
                            if(!(resultDict.ContainsKey(x.Key) && resultDict.ContainsValue(y.Key))
                                && !(resultDict.ContainsKey(y.Key) && resultDict.ContainsValue(x.Key) ))
                                    resultDict.Add(x.Key, y.Key);
                }
            }

            //Print the results
            foreach (var item in resultDict)
            {
                Console.WriteLine(String.Format("Anagrams of {0} : {1} - {2}", initialWord, item.Key, item.Value));
            }

            Console.ReadLine();
        }
开发者ID:Recognos,项目名称:RecognosInternship,代码行数:52,代码来源:Program.cs

示例7: agregarUsuariosMismoNombreDiccionario

 public void agregarUsuariosMismoNombreDiccionario()
 {
     Dictionary<int,UsuarioView> usuarios = new Dictionary<int, UsuarioView>();
     UsuarioView a = new UsuarioView(1, "a", "b", "c");
     UsuarioView c = new UsuarioView(2, "a", "b", "c");
     usuarios.Add(int.Parse(a.id), a);
     usuarios.Add(int.Parse(c.id), c);
     bool expected = true;
     bool expected1 = usuarios.ContainsValue(a);
     bool expected2 = usuarios.ContainsValue(c);
     Assert.AreEqual(expected1,expected);
     Assert.AreEqual(expected2, expected);
 }
开发者ID:louri91,项目名称:UAL_PSS201314,代码行数:13,代码来源:DiccionarioTest.cs

示例8: GetDataV2

        public static async Task<string> GetDataV2(RequestMethod method, string command, Dictionary<string, string> reqParams)
        {
            string json;

            if (reqParams != null && (reqParams.ContainsValue("True") || reqParams.ContainsValue("False")))
            {
                json = JsonConvert.SerializeObject(BoolDictionary(reqParams), Formatting.None);
            }
            else
            {
                json = JsonConvert.SerializeObject(reqParams, Formatting.None);
            }
            return await GetDataV2WithJson(method, command, json);
        }
开发者ID:rjb8682,项目名称:RedditClient,代码行数:14,代码来源:BryxHTTPHandler.cs

示例9: Main

        public static void Main(string[] args)
        {
            /* List Operations */

            List<int> list = new List<int>();

            list.Add (10);

            list.AddRange (new List<int> () { 20, 30, 40 });

            list.Remove (10);

            list.Insert (0, 10);

            list.Clear ();

            /* Dictionary Operations */

            Dictionary<int, string> dictionary = new Dictionary<int, string> ();

            dictionary.Add (1, "Sanjana");
            dictionary.Add (2, "Sumana");

            dictionary.ContainsValue ("Sanjana");
            dictionary.Remove (1);

            dictionary.Add (3, "Srinivas");

            dictionary.Clear ();
        }
开发者ID:vikram-v,项目名称:cts451792,代码行数:30,代码来源:Program.cs

示例10: Main

        static void Main(string[] args)
        {
            // Task: to convert the Dictionary collection "elements"
            //to List with keeping hierarchy of elements
            Dictionary<string, string> elements = new Dictionary<string, string>()
            {
                {"Tissue", "Organ"},
                {"Cell", "Cells"},
                {"System", "Body"},
                {"Cells", "Tissue"},
                {"Organ", "System"},
            };

            List<string> hierarchy = new List<string>();

            string first = elements.Keys.First(el => !elements.ContainsValue(el));
            hierarchy.Add(first);

            while (elements.ContainsKey(hierarchy.Last()))
                hierarchy.Add(elements[hierarchy.Last()]);

            foreach (var item in hierarchy)
                Console.WriteLine(item);

            Console.ReadKey();
        }
开发者ID:katecute,项目名称:MyProjects,代码行数:26,代码来源:Program.cs

示例11: IsIsomorphic

        private bool IsIsomorphic(string s, string t)
        {
            if (string.IsNullOrEmpty(s) && string.IsNullOrEmpty(t)) return true;

            int slength = s.Length;
            int tlength = t.Length;
            if (string.IsNullOrEmpty(s) || string.IsNullOrEmpty(t) || slength != tlength) return false;

            Dictionary<char, char> dic = new Dictionary<char, char>();
            for (int index = 0; index < slength; index++)
            {
                if (dic.ContainsKey(s[index]))
                {
                    if (dic[s[index]] != t[index])
                    {
                        return false;
                    }
                }
                else
                {
                    if (dic.ContainsValue(t[index]))
                    {
                        return false;
                    }
                    else
                    {
                        dic.Add(s[index], t[index]);
                    }
                }
            }
            return true;
        }
开发者ID:wenzhongtjgit,项目名称:LeetCode,代码行数:32,代码来源:205.IsomorphicStrings.cs

示例12: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        // Add your scenario description here
        TestLibrary.TestFramework.BeginScenario("PosTest2: Verify method ContainsValue(TValue) when the dictionary contains specified value .");

        try
        {
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.Add("txt", "notepad.exe");

            bool actual = dictionary.ContainsValue("notepad.exe");
            bool expected = true;
            if (actual != expected)
            {
                TestLibrary.TestFramework.LogError("001.1", "Method ContainsValue(TValue) Err.");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actual = " + actual + ", expected = " + expected);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:30,代码来源:dictionarycontainsvalue.cs

示例13: UniqueNumber

        private static string UniqueNumber(int[] arr)
        {
            string result = string.Empty;

            if (arr != null && arr.Length > 0 && arr.Length % 2 != 0)
            {
                Dictionary<int, int> count = new Dictionary<int, int>();

                for (int i = 0; i < arr.Length; i++)
                {
                    if (count.ContainsKey(arr[i]))
                    {
                        count[arr[i]]++;
                    }
                    else
                    {
                        count.Add(arr[i], 1);
                    }
                }

                if (count.ContainsValue(1))
                {
                    foreach (var item in count)
                    {
                        if (item.Value == 1)
                        {
                            result = item.Key.ToString();
                            break;
                        }
                    }
                }
            }

            return result;
        }
开发者ID:tarunbatta,项目名称:InterviewPreperationGuide,代码行数:35,代码来源:Question23.cs

示例14: Main

        public static void Main(string[] args)
        {
            /* List Operations */

            List<int> list = new List<int>();

            list.Add (1);
            list.Add (2);
            list.Add (3);

            list.Remove (1);

            list.Insert (0, 20);

            Console.WriteLine ("before clearing the list {0}",list.Count);
            list.Clear ();

            Console.WriteLine ("afetr clearing the list {0}",list.Count);

            /* Dictionary Operations */

            Dictionary<int, string> dictionary = new Dictionary<int, string> ();

            dictionary.Add (1, "xxx");
            dictionary.Add (2, "yyy");

            dictionary.ContainsValue ("yyy");
            dictionary.Remove (2);

            dictionary.Add (3, "zzz");
            Console.WriteLine ("before clearing the dictionary {0}",dictionary.Count);
            dictionary.Clear ();
            Console.WriteLine ("after clearing the dictionary {0}",dictionary.Count);
        }
开发者ID:ctsxamarintraining,项目名称:cts451892,代码行数:34,代码来源:Program.cs

示例15: PublishReusableWorkflow

        /// <summary>
        /// Publish Reusable Workflow
        /// </summary>
        /// <param name="mapping"></param>
        public void PublishReusableWorkflow(NWFMappingEntry mapping)
        {
            SPContentType ct = web.ContentTypes[mapping.BindingName];
            string workflowName = mapping.WorkflowName;
            string pathToNWF = Path.Combine(properties.Definition.RootDirectory, mapping.WorkflowFileName);
            byte[] workflowData = File.ReadAllBytes(pathToNWF);
            string workflowFile = Utility.ConvertByteArrayToString(workflowData);

            while ((int)workflowFile[0] != (int)char.ConvertFromUtf32(60)[0])
                workflowFile = workflowFile.Remove(0, 1);

            ExportedWorkflowWithListMetdata workflowWithListMetdata = ExportedWorkflowWithListMetdata.Deserialize(workflowFile);
            string xmlMessage = workflowWithListMetdata.ExportedWorkflowSeralized;
            SPListCollection lists = web.Lists;
            Dictionary<string, Guid> dictionary = new Dictionary<string, Guid>(lists.Count);
            foreach (SPList spList in lists)
            {
                if (!dictionary.ContainsKey(spList.Title.ToUpper()))
                    dictionary.Add(spList.Title.ToUpper(), spList.ID);
            }
            foreach (var listReference in workflowWithListMetdata.ListReferences)
            {
                string key = listReference.ListName.ToUpper();
                if (dictionary.ContainsKey(key) && !dictionary.ContainsValue(listReference.ListId))
                    xmlMessage = xmlMessage.Replace(Utility.FormatGuid(listReference.ListId), Utility.FormatGuid(dictionary[key]));
            }
            var exportedWorkflow = WorkflowPart.Deserialize<ExportedWorkflow>(xmlMessage);
            foreach (var config in exportedWorkflow.Configurations.ActionConfigs)
                WorkflowRenderer.ProcessActionConfig(config);

            Guid listId = Guid.Empty;
            bool validateWorkflow = true;
            Publish publish = new Publish(web);
            publish.PublishAWorkflow(workflowName, exportedWorkflow.Configurations, listId, web, (ImportContext)null, validateWorkflow, ct.Id, string.Empty);
        }
开发者ID:vgrem,项目名称:Blog-content,代码行数:39,代码来源:NWFAdapter.cs


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