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


C# HashTable.ContainesKey方法代码示例

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


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

示例1: Main

        public static void Main(string[] args)
        {
            LinkedList<KeyValuePair<string, int>> list = new LinkedList<KeyValuePair<string, int>>();
            Person person1 = new Person("Pesho", "Peshov", 21);
            Person person2 = new Person("Gosho", "Peshov", 22);
            Person person3 = new Person("Tosho", "Peshov", 23);

            // Console.WriteLine(person1.GetHashCode());
            // Console.WriteLine(person2.GetHashCode());
            // Console.WriteLine(person3.GetHashCode());
            // Console.WriteLine(person1.CompareTo(person2));
            // Console.WriteLine(person1.CompareTo(person3));
            var hashTable = new HashTable<Person, int>();
            hashTable.Add(person1, 1);
            hashTable.Add(person2, 1);
            hashTable.Add(person3, 2);
            foreach (KeyValuePair<Person, int> person in hashTable)
            {
                Console.WriteLine("Key\n{0}Value: {1}", person.Key, person.Value);
                Console.WriteLine();
            }

            Console.WriteLine("=====FIND=====");
            Console.WriteLine(hashTable.Find(person1));

            Console.WriteLine("=====REMOVE=====");
            Console.WriteLine(hashTable.Remove(person1));
            Console.WriteLine(hashTable.Remove(person1));

            Console.WriteLine("=====FIND=====");
            Console.WriteLine(hashTable.Find(person1));

            var keys = hashTable.Keys();
            foreach (var item in keys)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("=====INDEXER=====");
            Person person4 = new Person("Rosho", "Peshov", 55);

            // set
            hashTable[person4] = 777;

            // get
            Console.WriteLine(hashTable[person4]);

            Console.WriteLine("=====CLEAR=====");
            hashTable.Clear();
            Person person5 = new Person("Josh", "Goshov", 33);
            hashTable.Add(person5, 1234);
            Person person6 = new Person("Losh", "Goshov", 66);
            hashTable.Add(person6, 126);
            foreach (KeyValuePair<Person, int> person in hashTable)
            {
                Console.WriteLine("Key\n{0}Value: {1}", person.Key, person.Value);
                Console.WriteLine();
            }

            Console.WriteLine(hashTable.ContainesKey(person6));
            Console.WriteLine("=================================================");

            Console.WriteLine("=====HashSet=====");
            Hashset<Person> hashSet = new Hashset<Person>();
            hashSet.Add(person1);
            hashSet.Add(person2);
            Console.WriteLine(hashSet.Find(person1));
            Console.WriteLine(hashSet.Remove(person1));
            Console.WriteLine(hashSet.Find(person1));
            Console.WriteLine(hashSet.Find(person2));
            Console.WriteLine(hashSet.Remove(person2));

            Console.WriteLine("=====FOREACH=====");
            hashSet.Clear();
            hashSet.Add(person1);
            hashSet.Add(person2);
            foreach (var item in hashSet)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("=====UNION=====");
            var secondHashSet = new Hashset<Person>();
            secondHashSet.Add(person2);
            secondHashSet.Add(person3);
            var unionHashset = hashSet.Union(secondHashSet);
            foreach (var item in unionHashset)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("=====INTERSECT ====");
            var intersectionHashset = hashSet.Intersect(secondHashSet);
            foreach (var item in intersectionHashset)
            {
                Console.WriteLine(item);
            }
        }
开发者ID:bstaykov,项目名称:Telerik-DSA,代码行数:98,代码来源:Program.cs


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