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


C# HashSet.Find方法代码示例

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


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

示例1: ClearShouldRemoveElement

        public void ClearShouldRemoveElement()
        {
            var hashtable = new HashSet<int>();

            hashtable.Add(10);

            Assert.IsTrue(hashtable.Find(10));

            hashtable.Clear();

            Assert.IsFalse(hashtable.Find(10));
        }
开发者ID:Novkirishki,项目名称:Data-Structures-and-Algorithms,代码行数:12,代码来源:HashSetTests.cs

示例2: HashSetShouldFindElementsCorrectly

        public void HashSetShouldFindElementsCorrectly()
        {
            var set = new HashSet<int>();
            set.Add(0);
            set.Add(1);
            set.Add(2);
            set.Add(3);

            Assert.IsTrue(set.Find(0));
            Assert.IsTrue(set.Find(1));
            Assert.IsTrue(set.Find(2));
            Assert.IsTrue(set.Find(3));
            Assert.IsFalse(set.Find(4));
        }
开发者ID:atanas-georgiev,项目名称:Data-Structures-and-Algorithms-Homeworks,代码行数:14,代码来源:TestHashSet.cs

示例3: FindShouldReturnTrueForAddedElement

        public void FindShouldReturnTrueForAddedElement()
        {
            var hashtable = new HashSet<string>();

            hashtable.Add("aaa");

            Assert.IsTrue(hashtable.Find("aaa"));
        }
开发者ID:Novkirishki,项目名称:Data-Structures-and-Algorithms,代码行数:8,代码来源:HashSetTests.cs

示例4: HashSetShouldRemoveElementCorrectly

        public void HashSetShouldRemoveElementCorrectly()
        {
            var set = new HashSet<int>();
            set.Add(0);
            set.Remove(0);

            Assert.IsFalse(set.Find(0));
            Assert.AreEqual(0, set.Count);
        }
开发者ID:atanas-georgiev,项目名称:Data-Structures-and-Algorithms-Homeworks,代码行数:9,代码来源:TestHashSet.cs

示例5: Main

 static void Main(string[] args)
 {
     try
     {
         HashSet<int> set = new HashSet<int>();
         set.Add(13);
         set.Add(14);
         set.Add(15);
         set.Add(16);
         set.Add(17);
         Console.WriteLine(set.Find(14));
         Console.WriteLine("Count: {0}", set.Count);
         set.Remove(14);
         Console.WriteLine("Count: {0}", set.Count);
         Console.WriteLine(set.Find(14));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
开发者ID:Gardax,项目名称:CSharpExercises,代码行数:21,代码来源:HashSetMain.cs

示例6: Main

        public static void Main()
        {
            try
            {
                HashSet<int> hashSet = new HashSet<int>();

                hashSet.Add(1);
                hashSet.Add(5);
                hashSet.Add(2);
                hashSet.Add(33);
                Console.WriteLine("Count is : {0}", hashSet.Count);

                hashSet.Remove(2);
                Console.WriteLine("Count is : {0}", hashSet.Count);

                Console.WriteLine(hashSet.Find(5));
                Console.WriteLine(hashSet.Contains(5));

                int[] numArray = new int[] { 5, 11, 33 };
                int[] array = numArray;
                hashSet.UnionWith(array);
                Console.WriteLine("Count is : {0}", hashSet.Count);

                int[] numArray1 = new int[] { 5, 11, 22 };
                int[] array2 = numArray1;
                hashSet.Intersect(array2);
                Console.WriteLine("Count is : {0}", hashSet.Count);

                hashSet.Clear();
                Console.WriteLine("Count is : {0}", hashSet.Count);
                Console.WriteLine(hashSet.Find(5));
            }
            catch (ArgumentException aex)
            {
                Console.WriteLine(aex.Message);
            }
        }
开发者ID:niki-funky,项目名称:Telerik_Academy,代码行数:37,代码来源:Demo.cs

示例7: Main

        static void Main(string[] args)
        {
            HashSet<string> hashSet = new HashSet<string>();

            hashSet.Add("ooo");
            hashSet.Add("qqq");
            hashSet.Add("ppp");
            hashSet.Add("iii");

            foreach (var item in hashSet.Items)
            {
                Console.WriteLine(item);
            }

            hashSet.Remove("iii");
            Console.WriteLine("\nCount after removal: {0}", hashSet.Count);


            Console.WriteLine();
            Console.WriteLine(hashSet.Find("ppp"));


            HashSet<string> secondHashSet = new HashSet<string>();
            secondHashSet.Add("www");
            secondHashSet.Add("qqq");
            secondHashSet.Add("yyy");
            secondHashSet.Add("ooo");

            Console.WriteLine("\nUnion: ");
            HashSet<string> union = hashSet.Union(secondHashSet);
            foreach (var item in union.Items)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("\nIntersection: ");
            HashSet<string> intersection = hashSet.Intersect(secondHashSet);
            foreach (var item in intersection.Items)
            {
                Console.WriteLine(item);
            }
        }
开发者ID:Dyno1990,项目名称:TelerikAcademy-1,代码行数:42,代码来源:SetImplementation.cs

示例8: Main

        static void Main(string[] args)
        {
            IHashSet<int> sampleOne = new HashSet<int>();
           
            sampleOne.Add(1);
            sampleOne.Add(1);
            sampleOne.Add(2);
            sampleOne.Add(3);
            sampleOne.Add(4);
            sampleOne.Add(5);
            sampleOne.Add(6);
            sampleOne.Add(7);
            sampleOne.Add(8);
            sampleOne.Add(9);

             IHashSet<int> sampleTwo = new HashSet<int>();

            sampleTwo.Add(1);
            sampleTwo.Add(2);
            sampleTwo.Add(9);
            sampleTwo.Add(100);


            Console.WriteLine("sampleOne:");
            foreach (var item in sampleOne)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("sampleTwo:");
            foreach (var item in sampleTwo)
            {
                Console.WriteLine(item);
            }


            IHashSet<int> intersected = sampleOne.Intersect(sampleTwo);

            Console.WriteLine("Intesected of sampleOne and sampleTwo:");
            foreach (var item in intersected)
            {
                Console.WriteLine(item);
            }

            IHashSet<int> union = sampleOne.Union(sampleTwo);

            Console.WriteLine("Union of sampleOne and sampleTwo:");
            foreach (var item in union)
            {
                Console.WriteLine(item);
            }

            int founded = sampleOne.Find(1);
            Console.WriteLine("Look for '1':" + founded);

            Console.WriteLine("Count:" + sampleOne.Count);
            sampleOne.Remove(3);
            sampleOne.Clear();
            Console.WriteLine("Count after clear:" + sampleOne.Count);

        }
开发者ID:vaster,项目名称:Telerik.vasko,代码行数:61,代码来源:Program.cs

示例9: FindShouldReturnFalseIfKeyIsNotAdded

        public void FindShouldReturnFalseIfKeyIsNotAdded()
        {
            var hashtable = new HashSet<string>();

            Assert.IsFalse(hashtable.Find("aaa"));
        }
开发者ID:Novkirishki,项目名称:Data-Structures-and-Algorithms,代码行数:6,代码来源:HashSetTests.cs

示例10: RemoveShouldWorkProperly

        public void RemoveShouldWorkProperly()
        {
            var hashtable = new HashSet<int>();

            hashtable.Add(10);

            Assert.IsTrue(hashtable.Find(10));

            hashtable.Remove(10);

            Assert.IsFalse(hashtable.Find(10));
        }
开发者ID:Novkirishki,项目名称:Data-Structures-and-Algorithms,代码行数:12,代码来源:HashSetTests.cs


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