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


C# HashedSet类代码示例

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


HashedSet类属于命名空间,在下文中一共展示了HashedSet类的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 set = new HashedSet<int>();

            for (int i = 1; i < 11; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    set.Add(i);
                }
            }

            System.Console.WriteLine(set);
            System.Console.WriteLine(set.Count);

            var otherSet = new HashedSet<int>();

            for (int i = 5; i < 16; i++)
            {
                otherSet.Add(i);
            }

            System.Console.WriteLine(otherSet);
            System.Console.WriteLine(otherSet.Count);
            System.Console.WriteLine(set.IntersectsWith(otherSet));
            System.Console.WriteLine(set.Union(otherSet));
        }
开发者ID:RuzmanovDev,项目名称:TelerikAcademy,代码行数:27,代码来源:Startup.cs

示例3: GetClassEntries

		/// <summary>
		/// Returns a collection of <see cref="ClassEntry" /> containing
		/// information about all classes in this stream.
		/// </summary>
		/// <param name="document">A validated <see cref="XmlDocument"/> representing
		/// a mapping file.</param>
		public static ICollection GetClassEntries(XmlDocument document)
		{
			XmlNamespaceManager nsmgr = HbmBinder.BuildNamespaceManager(document.NameTable);

			// Since the document is validated, no error checking is done in this method.
			HashedSet classEntries = new HashedSet();

			XmlNode root = document.DocumentElement;

			string assembly = XmlHelper.GetAttributeValue(root, "assembly");
			string @namespace = XmlHelper.GetAttributeValue(root, "namespace");

			XmlNodeList classNodes = document.SelectNodes(
				"//" + HbmConstants.nsClass +
				"|//" + HbmConstants.nsSubclass +
				"|//" + HbmConstants.nsJoinedSubclass +
				"|//" + HbmConstants.nsUnionSubclass,
				nsmgr
				);

			foreach (XmlNode classNode in classNodes)
			{
				string name = XmlHelper.GetAttributeValue(classNode, "name");
				string extends = XmlHelper.GetAttributeValue(classNode, "extends");
				ClassEntry ce = new ClassEntry(extends, name, assembly, @namespace);
				classEntries.Add(ce);
			}

			return classEntries;
		}
开发者ID:Novthirteen,项目名称:sconit_timesseiko,代码行数:36,代码来源:ClassExtractor.cs

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

示例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()
        {
            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

示例7: Task

 public Task()
 {
     CreatedDate = ModifiedDate = DateTimeHelper.Now;
     Id = Guid.NewGuid();
     _title = "";
     Links = new HashedSet<Link>();
 }
开发者ID:ArildF,项目名称:PTB,代码行数:7,代码来源:Task.cs

示例8: ProductQuotation

 public ProductQuotation(Quotation quotation, string name, string group)
 {
     Quotation = quotation;
     Name = name;
     Group = group;
     Editions = new HashedSet<EditionQuotation>();
 }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:7,代码来源:ProductQuotation.cs

示例9: Main

 static void Main(string[] args)
 {
     ISessionFactory sf = CreateSessionFactory();
     using(ISession s = sf.OpenSession()) {
         using(ITransaction t = s.BeginTransaction()) {
             ISet<T3> t3 = new HashedSet<T3>() {
                 new T3() {str="a"},
                 new T3() {str="b"},
                 new T3() {str="c"}
             };
             foreach(T3 tt3 in t3)
                 s.Save(tt3);
             T1 t1 = new T1() {
                 str = "t1",
                 t3 = t3
             };
             T2 t2 = new T2() {
                 str = "t2",
                 t3 = t3
             };
             s.Save(t1);
             s.Save(t2);
             t.Commit();
             //IList<T1> k = s.QueryOver<T1>().List();
             //Console.WriteLine(k[0].id);
             //s.Delete(k[0]);
             //t.Commit();
         }
     }
     Console.ReadKey();
 }
开发者ID:KenjiTakahashi,项目名称:bazodanowe,代码行数:31,代码来源:Program.cs

示例10: InitializerShouldCreateEmptyHashedSet

        public void InitializerShouldCreateEmptyHashedSet()
        {
            var set = new HashedSet<int>();
            int expected = 0;

            Assert.AreEqual(expected, set.Count);
        }
开发者ID:vassildinev,项目名称:Data-Structures-and-Algorithms,代码行数:7,代码来源:HashedSetTests.cs

示例11: TestFindWithInvalidKey

        public void TestFindWithInvalidKey()
        {
            var table = new HashedSet<string>();
            table.Add("Pesho");

            var value = table.Find("Peho");
        }
开发者ID:TeeeeeC,项目名称:TelerikAcademy2015-2016,代码行数:7,代码来源:HashedSetTests.cs

示例12: TestFindShouldProperlyWork

        public void TestFindShouldProperlyWork()
        {
            var table = new HashedSet<string>();
            table.Add("Pesho");

            Assert.AreEqual(true, table.Find("Pesho"));
        }
开发者ID:TeeeeeC,项目名称:TelerikAcademy2015-2016,代码行数:7,代码来源:HashedSetTests.cs

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

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

示例15: Distinct

		public IEnumerable Distinct(IEnumerable source)
		{
			var s = new HashedSet();
			foreach (object item in source)
				s.Add(item);
			return s;
		}
开发者ID:elementar,项目名称:Suprifattus.Util,代码行数:7,代码来源:ListHelper.cs


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