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


C# HashedSet.Remove方法代码示例

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


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

示例1: Main

        public static void Main()
        {
            var firstSet = new HashedSet<string>();
            var secondSet = new HashedSet<string>();

            firstSet.Add("Pesho");
            firstSet.Add("Gosho");
            firstSet.Add("Tosho");

            secondSet.Add("Ivan");
            secondSet.Add("Petkan");
            secondSet.Add("Dragan");

            Console.WriteLine(firstSet);
            Console.WriteLine(secondSet);

            Console.WriteLine(firstSet.Intersect(secondSet));
            Console.WriteLine(secondSet.Intersect(firstSet));

            Console.WriteLine(firstSet.Union(secondSet));
            Console.WriteLine(secondSet.Union(firstSet));

            firstSet.Remove("Pesho");
            firstSet.Remove("Tosho");
            Console.WriteLine(firstSet);

            Console.WriteLine(firstSet.Find("Tosho"));
            Console.WriteLine(firstSet.Find("Gosho"));

            Console.WriteLine(firstSet.Count);
        }
开发者ID:MarinMarinov,项目名称:Data-structures-and-algorithms,代码行数:31,代码来源:Startup.cs

示例2: Main

    /* 5 Implement the data structure "set" in a class HashedSet<T> using your class HashTable<K,T>
     * to hold the elements. Implement all standard set operations like Add(T), Find(T), Remove(T),
     * Count, Clear(), union and intersect.
     * */
    static void Main(string[] args)
    {
        var set = new HashedSet<int>();

        Debug.Assert(set.Count == 0);
        Debug.Assert(!set.Find(1));

        set.Add(1);

        Debug.Assert(set.Count == 1);
        Debug.Assert(set.Find(1));

        set.Add(2);

        Debug.Assert(set.Count == 2);
        Debug.Assert(set.Find(2));

        set.Add(1);

        Debug.Assert(set.Count == 2);
        Debug.Assert(set.Find(1));

        set.Remove(1);

        Debug.Assert(set.Count == 1);
        Debug.Assert(!set.Find(1));
        Debug.Assert(set.Find(2));

        var set1 = new HashedSet<int> { 1, 2, 3, 4, 5, 6 }.Intersect(new HashedSet<int> { 2, 4, 6, 8, 10 });
        Debug.Assert(set1.SameContents(new[] { 2, 4, 6 }, i => i));

        var set2 = new HashedSet<int> { 1, 2, 3, 4, 5, 6 }.Union(new HashedSet<int> { 2, 4, 6, 8, 10 });
        Debug.Assert(set2.SameContents(new[] { 1, 2, 3, 4, 5, 6, 8, 10 }, i => i));
    }
开发者ID:staafl,项目名称:ta-hw-dsa,代码行数:38,代码来源:program.cs

示例3: Main

        static void Main()
        {
            HashedSet<string> myBestFriends = new HashedSet<string>();

            myBestFriends.Add("Ivan");
            myBestFriends.Add("Daniel");
            myBestFriends.Add("Cecilia");

            Console.WriteLine(myBestFriends.Count);

            myBestFriends.Remove("Cecilia");
            Console.WriteLine(myBestFriends.Count);

            HashedSet<string> yourBestFriends = new HashedSet<string>();

            yourBestFriends.Add("Petar");
            yourBestFriends.Add("Daniel");
            yourBestFriends.Add("Monika");

            HashedSet<string> allBestFriends = myBestFriends.Union(yourBestFriends);

            Console.WriteLine("All best friends: ");
            foreach (var item in allBestFriends.setOfData)
            {
                Console.WriteLine("{0}", item.Value);
            }

            HashedSet<string> mutualBestFriends = myBestFriends.Intersect(yourBestFriends);

            Console.WriteLine("Mutual best friends: ");
            foreach (var item in mutualBestFriends.setOfData)
            {
                Console.WriteLine("{0}", item.Value);
            }
        }
开发者ID:VDGone,项目名称:TelerikAcademy-2,代码行数:35,代码来源:EntryPoint.cs

示例4: Main

        public static void Main(string[] args)
        {
            HashedSet<string> students = new HashedSet<string>();
            students.Add("Pesho");
            students.Add("Pesho");
            students.Add("Gosho");
            students.Remove("Gosho");
            students.Add("Misho");
            students.Add("Ivan");
            Console.WriteLine("Student count: {0}", students.Count);

            HashedSet<string> users = new HashedSet<string>();
            users.Add("Mariq");
            users.Add("Pesho");
            users.Add("Misho");

            HashedSet<string> intersection = students.Intersect(users);
            Console.WriteLine("Intersection:");
            foreach (var name in intersection)
            {
                Console.WriteLine(name);
            }

            HashedSet<string> union = students.Union(users);
            Console.WriteLine("Union: ");
            foreach (var name in union)
            {
                Console.WriteLine(name);
            }
        }
开发者ID:nader-dab,项目名称:CSharp-Homeworks,代码行数:30,代码来源:Program.cs

示例5: Main

        static void Main()
        {
            var set = new HashedSet<int>();

            set.Add(5);
            set.Add(3);
            set.Add(-4);
            set.Add(12);
            set.Add(0);
            set.Add(-50);
            set.Add(10);
            Console.WriteLine("Set contains 12 -> {0}", set.Find(12));
            Console.WriteLine("Set contains 13 -> {0}", set.Find(13));
            set.Remove(10);
            Console.WriteLine("Removed 10\nSet contains 10 -> {0}", set.Find(10));
            Console.WriteLine("Set contains {0} items", set.Count);
            Console.WriteLine("Set 1: {0}", set);

            var anotherSet = new HashedSet<int>();
            anotherSet.Add(-4);
            anotherSet.Add(15);
            anotherSet.Add(0);
            anotherSet.Add(-122);
            anotherSet.Add(35);
            Console.WriteLine("Set 2: {0}", anotherSet);

            set.Union(anotherSet);
            Console.WriteLine("Set after union: {0}", set);

            set.Intersect(anotherSet);
            Console.WriteLine("Set after intersect: {0}", set);

            set.Clear();
            Console.WriteLine("Set contains {0} items after clear", set.Count);
        }
开发者ID:Moiraines,项目名称:TelerikAcademy,代码行数:35,代码来源:StartUp.cs

示例6: Main

    public static void Main()
    {
        HashedSet<float> firstSet = new HashedSet<float>();
        firstSet.Add(1f);
        firstSet.Add(1.4f);
        firstSet.Add(1.7f);
        firstSet.Add(2f);
        firstSet.Add(2.2f);
        firstSet.Remove(1.7f);
        Console.WriteLine(firstSet.Find(1f));
        Console.WriteLine(firstSet.Count);

        HashedSet<float> secondSet = new HashedSet<float>();
        secondSet.Add(1f);
        secondSet.Add(2f);
        secondSet.Add(3f);
        secondSet.Add(5f);

        HashedSet<float> thirdSet = new HashedSet<float>();
        thirdSet.Add(1f);
        thirdSet.Add(2f);
        thirdSet.Add(3f);
        thirdSet.Add(5f);

        secondSet.Union(firstSet);
        thirdSet.Intersect(firstSet);
        firstSet.Clear();
    }
开发者ID:vasilkrvasilev,项目名称:DataStructuresAlgorithms,代码行数:28,代码来源:Example.cs

示例7: ShouldRemoveElementsCorrectly

 public void ShouldRemoveElementsCorrectly()
 {
     var set = new HashedSet<int>();
     set.Add(5);
     Assert.AreEqual(1, set.Count);
     set.Remove(5);
     Assert.AreEqual(0, set.Count);
 }
开发者ID:RuzmanovDev,项目名称:TelerikAcademy,代码行数:8,代码来源:HashedSetTests.cs

示例8: RandomAddDelete

        public void RandomAddDelete()
        {
            const int SIZE = 50000;
            bool[] present = new bool[SIZE];
            Random rand = new Random();
            HashedSet<int> set1 = new HashedSet<int>();
            bool b;

            // Add and delete values at random.
            for (int i = 0; i < SIZE * 10; ++i)
            {
                int v = rand.Next(SIZE);
                if (present[v])
                {
                    Assert.IsTrue(set1.Contains(v));
                    b = set1.Remove(v);
                    Assert.IsTrue(b);
                    present[v] = false;
                }
                else
                {
                    Assert.IsFalse(set1.Contains(v));
                    b = set1.Add(v);
                    Assert.IsTrue(b);
                    present[v] = true;
                }
            }

            int count = 0;
            foreach (bool x in present)
            {
                if (x)
                {
                    ++count;
                }
            }

            Assert.AreEqual(count, set1.Count);

            // Make sure the set has all the correct values, not in order.
            foreach (int v in set1)
            {
                Assert.IsTrue(present[v]);
                present[v] = false;
            }

            // Make sure all were found.
            count = 0;
            foreach (bool x in present)
            {
                if (x)
                {
                    ++count;
                }
            }

            Assert.AreEqual(0, count);
        }
开发者ID:VesiBaleva,项目名称:TelerikAcademy,代码行数:58,代码来源:HashedSetTest.cs

示例9: RemoveFromHashSetMustWork

        public void RemoveFromHashSetMustWork()
        {
            var hashedSet = new HashedSet<int>();

            var key = 10;

            hashedSet.Add(key);
            hashedSet.Remove(key);

            Assert.AreEqual(hashedSet.Count(), 0);
        }
开发者ID:p0150n,项目名称:TelerikAcademy,代码行数:11,代码来源:HashedSetTests.cs

示例10: RemoveShouldDeleteElementCorrectly

        public void RemoveShouldDeleteElementCorrectly()
        {
            var set = new HashedSet<string>();

            for (int i = 0; i < 20; i++)
            {
                set.Add(string.Format("pesho #{0}", i % 5));
            }

            set.Remove("pesho #3");

            Assert.AreEqual(4, set.Count);
            Assert.IsFalse(set.Contains("pesho #3"));
        }
开发者ID:NikitoG,项目名称:TelerikAcademyHomeworks,代码行数:14,代码来源:HashSetTests.cs

示例11: Main

    static void Main()
    {
        HashedSet<int> set = new HashedSet<int>();
        set.Add(5);
        set.Add(5);
        set.Add(6);
        set.Add(1);
        set.Add(3);
        set.Add(3);
        set.Add(8);
        set.Remove(6);

        Console.WriteLine("First set contains 6 - {0}", set.Contains(6));
        Console.WriteLine("First set contains 8 - {0}", set.Contains(8));

        Console.WriteLine("First set");
        foreach (var item in set)
        {
            Console.Write("{0} ", item);
        }
        Console.WriteLine();

        Console.WriteLine("Second set");
        HashedSet<int> set2 = new HashedSet<int>();
        set2.Add(13);
        set2.Add(3);
        set2.Add(1);
        foreach (var item in set2)
        {
            Console.Write("{0} ", item);
        }
        Console.WriteLine();

        HashedSet<int> union = set.UnionWith(set2);
        Console.WriteLine("Union: ");
        foreach (var item in union)
        {
            Console.Write("{0} ", item);
        }
        Console.WriteLine();

        HashedSet<int> intersection = set.IntersectWith(set2);
        Console.WriteLine("Intersection: ");
        foreach (var item in intersection)
        {
            Console.Write("{0} ", item);
        }
        Console.WriteLine();
    }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:49,代码来源:Program.cs

示例12: Main

        static void Main()
        {
            HashedSet<string> set = new HashedSet<string>();

            set.Add("Pesho");
            set.Add("Gosho");
            set.Add("Tisho", true);
            set.Add("ToRemove");
            set.Add("Petko");
            set.Remove("ToRemove");

            foreach (var item in set)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("Total count = " + set.Count);
        }
开发者ID:psotirov,项目名称:TelerikAcademyProjects,代码行数:17,代码来源:HashedSetProgram.cs

示例13: Main

 internal static void Main()
 {
     HashedSet<int> test = new HashedSet<int>();
     HashedSet<int> other = new HashedSet<int>();
     test.Add(1);
     test.Add(2);
     test.Add(3);
     test.Add(4);
     test.Add(5);
     test.Add(6);
     other.Add(4);
     other.Add(5);
     other.Add(6);
     other.Add(7);
     other.Add(8);
     Console.WriteLine("Initial hash set:");
     Console.WriteLine(string.Join(", ", test));
     Console.WriteLine("--------------------------------------------------------------");
     Console.WriteLine("After removal of 3:");
     test.Remove(3);
     Console.WriteLine(string.Join(", ", test));
     Console.WriteLine("--------------------------------------------------------------");
     Console.WriteLine("Is 1 found? {0}", test.Find(1));
     Console.WriteLine("Is 3 found? {0}", test.Find(3));
     Console.WriteLine("--------------------------------------------------------------");
     Console.WriteLine("First hash set:");
     Console.WriteLine(string.Join(", ", test));
     Console.WriteLine("Member count: {0}", test.Count);
     Console.WriteLine("--------------------------------------------------------------");
     Console.WriteLine("Second hash set:");
     Console.WriteLine(string.Join(", ", other));
     Console.WriteLine("Member count: {0}", other.Count);
     Console.WriteLine("--------------------------------------------------------------");
     Console.WriteLine("Intersect of the first and second:");
     Console.WriteLine(string.Join(", ", test.Intersect(other)));
     Console.WriteLine("--------------------------------------------------------------");
     Console.WriteLine("Union of the first and second:");
     Console.WriteLine(string.Join(", ", test.Union(other)));
     Console.WriteLine("--------------------------------------------------------------");
     test.Clear();
     Console.WriteLine("First hash set after clear:");
     Console.WriteLine(string.Join(", ", test));
 }
开发者ID:kalinalazarova1,项目名称:TelerikAcademy,代码行数:43,代码来源:HashedSetTest.cs

示例14: Main

        static void Main()
        {
            HashedSet<int> hSet = new HashedSet<int>();

            hSet.Add(5);
            hSet.Add(15);
            hSet.Add(5);

            Console.WriteLine(hSet.Find(45));
            Console.WriteLine(hSet.Find(15));
            hSet.Remove(5);
            Console.WriteLine(hSet.Find(5));

            hSet.Clear();

            Console.WriteLine(hSet.Count);

            hSet.Add(5);
            hSet.Add(15);
            hSet.Add(25);
            hSet.Add(35);

            HashedSet<int> hSetTwo = new HashedSet<int>();
            hSetTwo.Add(4);
            hSetTwo.Add(24);
            hSetTwo.Add(25);
            hSetTwo.Add(35);

            var newIntersectedSet = hSet.Intersect(hSetTwo);

            foreach (var item in newIntersectedSet.Keys)
            {
                Console.WriteLine(item);
            }

            var newUnitedSet = hSet.Union(hSetTwo);

            foreach (var item in newUnitedSet.Keys)
            {
                Console.WriteLine(item);
            }
        }
开发者ID:NikolovNikolay,项目名称:Telerik-Homeworks,代码行数:42,代码来源:HashedSetTesting.cs

示例15: Main

    static void Main()
    {
        HashedSet<int> hashSet1 = new HashedSet<int>();

        for (int i = 0; i < 10; i++)
        {
            hashSet1.Add(i);
        }

        Console.WriteLine("Find element with key = 4");
        Console.WriteLine(hashSet1.Find(4));

        Console.WriteLine("Find element with key = 2 and write the count of elements");
        hashSet1.Remove(2);
        Console.WriteLine(hashSet1.Count);

        HashedSet<int> hashSet2 = new HashedSet<int>();
        hashSet2.Add(5);
        hashSet2.Add(9);
        hashSet2.Add(33);

        Console.WriteLine("Union: ");
        hashSet1.UnionWith(hashSet2);
        for (int i = 0; i < hashSet1.Container.Count; i++)
        {
            Console.WriteLine(hashSet1.Container.Keys[i]);
        }
        Console.WriteLine();

        Console.WriteLine("Intersect: ");
        hashSet1.IntersectWith(hashSet2);

        for (int i = 0; i < hashSet1.Container.Count; i++)
        {
            Console.WriteLine(hashSet1.Container.Keys[i]);
        }
        Console.WriteLine();

        Console.WriteLine("count after clear");
        hashSet2.Clear();
        Console.WriteLine(hashSet2.Container.Count);
    }
开发者ID:hristo11111,项目名称:TelerikAcademy-HristoBratanov,代码行数:42,代码来源:TestHashSet.cs


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