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


C# HashedSet.Add方法代码示例

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


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

示例1: 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

示例2: 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

示例3: Union_Test

        public void Union_Test()
        {
            HashedSet<int> set = new HashedSet<int>();
            HashedSet<int> otherSet = new HashedSet<int>();

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

            otherSet.Add(3);
            otherSet.Add(4);
            otherSet.Add(5);

            set.Union(otherSet);

            StringBuilder actual = new StringBuilder();
            foreach (var item in set)
            {
                actual.Append(item + " ");
            }

            string expected = "1 2 3 4 5 ";

            Assert.AreEqual(expected, actual.ToString());
        }
开发者ID:elibk,项目名称:DSA,代码行数:25,代码来源:HashedSetTest.cs

示例4: 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

示例5: test

		public void test()
		{
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				Person person = new Person("1");
				person.Name = "John Doe";
				var set = new HashedSet<object>();
				set.Add("555-1234");
				set.Add("555-4321");
				person.Properties.Add("Phones", set);

				s.Save(person);
				tx.Commit();
			}
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				Person person = (Person)s.CreateCriteria(typeof(Person)).UniqueResult();

				Assert.AreEqual("1", person.ID);
				Assert.AreEqual("John Doe", person.Name);
				Assert.AreEqual(1, person.Properties.Count);
				Assert.That(person.Properties["Phones"], Is.InstanceOf<ISet<object>>());
				Assert.IsTrue(((ISet<object>) person.Properties["Phones"]).Contains("555-1234"));
				Assert.IsTrue(((ISet<object>) person.Properties["Phones"]).Contains("555-4321"));
			}
		}
开发者ID:nikson,项目名称:nhibernate-core,代码行数:28,代码来源:Fixture.cs

示例6: Main

        static void Main()
        {
            var mySet = new HashedSet<string>();
            mySet.Add("string");
            mySet.Add("str");
            //mySet.Add(null);
            mySet.Add("strength");
            mySet.Add("string");

            //var strength = mySet.Find("strength");
            //Console.WriteLine(strength);

            //var isStringRemoved = mySet.Remove("string");
            //Console.WriteLine(isStringRemoved);

            var mySecondSet = new HashedSet<string>();
            mySecondSet.Add("strength");
            mySecondSet.Add("dexterity");
            mySecondSet.Add("intelligence");

            mySet.Union(mySecondSet);
            //mySet.Intersect(mySecondSet);
            foreach (var item in mySet)
            {
                Console.WriteLine(item);
            }
        }
开发者ID:NK-Hertz,项目名称:Telerik-Academy-2015,代码行数:27,代码来源:MyHashSetStartUp.cs

示例7: 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

示例8: 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

示例9: AddShouldNotThrowExceptionWhenTheSameKeyIsAlreadyPresent

        public void AddShouldNotThrowExceptionWhenTheSameKeyIsAlreadyPresent()
        {
            var hashedset = new HashedSet<string>();

            hashedset.Add("gosho");
            hashedset.Add("gosho");
        }
开发者ID:KonstantinSimeonov,项目名称:Studying-with-Pesho-and-Mimeto,代码行数:7,代码来源:HashedSetTests.cs

示例10: 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

示例11: TestAddMethod

 public void TestAddMethod()
 {
     var hashedSet = new HashedSet<int>();
     Assert.IsTrue(hashedSet.Add(1));
     Assert.IsTrue(hashedSet.Add(2));
     Assert.IsFalse(hashedSet.Add(2));
     Assert.AreEqual(2, hashedSet.Count);
 }
开发者ID:g-yonchev,项目名称:Telerik-Academy,代码行数:8,代码来源:05.HashSetTests.cs

示例12: BuildSearcher

        public static IndexSearcher BuildSearcher(ISearchFactoryImplementor searchFactory,
                                             out ISet<System.Type> classesAndSubclasses,
                                             params System.Type[] classes)
        {
            IDictionary<System.Type, DocumentBuilder> builders = searchFactory.DocumentBuilders;
            ISet<IDirectoryProvider> directories = new HashedSet<IDirectoryProvider>();
            if (classes == null || classes.Length == 0)
            {
                // no class means all classes
                foreach (DocumentBuilder builder in builders.Values)
                {
                    foreach (IDirectoryProvider provider in builder.DirectoryProvidersSelectionStrategy.GetDirectoryProvidersForAllShards())
                    {
                        directories.Add(provider);
                    }
                }

                // Give them back an empty set
                classesAndSubclasses = null;
            }
            else
            {
                ISet<System.Type> involvedClasses = new HashedSet<System.Type>();
                involvedClasses.AddAll(classes);
                foreach (System.Type clazz in classes)
                {
                    DocumentBuilder builder;
                    builders.TryGetValue(clazz, out builder);
                    if (builder != null)
                    {
                        involvedClasses.AddAll(builder.MappedSubclasses);
                    }
                }

                foreach (System.Type clazz in involvedClasses)
                {
                    DocumentBuilder builder;
                    builders.TryGetValue(clazz, out builder);

                    // TODO should we rather choose a polymorphic path and allow non mapped entities
                    if (builder == null)
                    {
                        throw new HibernateException("Not a mapped entity: " + clazz);
                    }

                    foreach (IDirectoryProvider provider in builder.DirectoryProvidersSelectionStrategy.GetDirectoryProvidersForAllShards())
                    {
                        directories.Add(provider);
                    }
                }

                classesAndSubclasses = involvedClasses;
            }

            IDirectoryProvider[] directoryProviders = new List<IDirectoryProvider>(directories).ToArray();
            return new IndexSearcher(searchFactory.ReaderProvider.OpenReader(directoryProviders));
        }
开发者ID:spib,项目名称:nhcontrib,代码行数:57,代码来源:FullTextSearchHelper.cs

示例13: IntersectShouldReturnCollectionWithRepeatValues

        public void IntersectShouldReturnCollectionWithRepeatValues()
        {
            HashedSet<string> set = new HashedSet<string>();
            set.Add("value 1");
            set.Add("Pesho");
            var resultSet = hashedSet.Intersect(set);

            Assert.AreEqual(1, resultSet.Count());
        }
开发者ID:VDGone,项目名称:TelerikAcademy-1,代码行数:9,代码来源:HashedSetTests.cs

示例14: ShouldCorrectlyAddAllValues

        public void ShouldCorrectlyAddAllValues()
        {
            var set = new HashedSet<int>();
            set.Add(1);
            set.Add(3);
            set.Add(5);
            set.Add(7);
            set.Add(9);

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

示例15: ShouldNotAddDuplicateValues

        public void ShouldNotAddDuplicateValues()
        {
            var set = new HashedSet<int>();
            set.Add(1);
            set.Add(1);
            set.Add(1);
            set.Add(1);
            set.Add(1);

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


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