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


C# Set.Add方法代码示例

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


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

示例1: SecondAdd

 public void SecondAdd()
 {
     Set<int> set = new Set<int>();
       set.Add(1);
       set.Add(2);
       Assert.AreEqual(2, set.Count);
 }
开发者ID:Felixdev,项目名称:dogfight2008,代码行数:7,代码来源:SetFixture.cs

示例2: AddWithDelegatePositiveTest

 public void AddWithDelegatePositiveTest()
 {
     ISet<string> sets = new Set<string>();
     sets.Add("item1");
     sets.Add("item22", (i,j) => i.Length == j.Length);
     Assert.AreEqual(2, sets.Count);
 }
开发者ID:Roman-M,项目名称:MentoringProgramm,代码行数:7,代码来源:ISetUnitTests.cs

示例3: BFS

        /*************************/
        // Selecting initial vertices
        /*************************/
        // Returns a vertex on the last level of a Breadth-first search (BFS)
        public static int BFS(Graph graph, int init)
        {
            // BFS working queue
            Queue<int> queue = new Queue<int>();
            // Vertices that have already been visited
            Set<int> visited = new Set<int>();

            // Initial vertex is given as input
            visited.Add(init);
            queue.Enqueue(init);
            int current = init;

            // While there is still a vertex in the queue...
            while (queue.Count > 0)
            {
                //... select the first vertex and process it
                current = queue.Dequeue();
                foreach (int w in graph.OpenNeighborhood(current))
                {
                    // Enqueue all neighbors that have not been processed yet
                    if (!visited.Contains(w))
                    {
                        visited.Add(w);
                        queue.Enqueue(w);
                    }
                }
            }
            // This is the last vertex that has been processed, thus a vertex that is on the last level of the BFS search
            return current;
        }
开发者ID:FrankvH,项目名称:BooleanWidth,代码行数:34,代码来源:Heuristics.cs

示例4: Main

        static void Main()
        {
            var setOne = new Set<int>();
            setOne.Add(5);
            setOne.Add(5);
            setOne.Add(5);
            setOne.Add(5);
            setOne.Add(5);
            setOne.Add(5);
            setOne.Add(5);
            setOne.Add(5);
            setOne.Add(5);
            setOne.Add(6);

            var setTwo = new Set<int>();
            setTwo.Add(5);
            setTwo.Add(10);

            Console.WriteLine(setOne);
            Console.WriteLine(setTwo);

            var union = setOne.Union(setTwo);

            Console.WriteLine();
            Console.WriteLine(union);

            var intersect = setOne.Intersect(setTwo);

            Console.WriteLine(intersect);
        }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:30,代码来源:Startup.cs

示例5: Main

        public static void Main()
        {
            var set1 = new Set<string>();
            var set2 = new Set<string>();

            set1.Add("one");
            set1.Add("two");
            set1.Add("three");

            set2.Add("three");
            set2.Add("four");

            Console.WriteLine(set1);
            Console.WriteLine(set2);

            Console.WriteLine(set1.Intersect(set2));
            Console.WriteLine(set2.Intersect(set1));

            Console.WriteLine(set1.Union(set2));
            Console.WriteLine(set2.Union(set1));

            set1.Remove("five");
            set1.Remove("two");
            Console.WriteLine(set1);

            Console.WriteLine(set1.Find("one"));
            Console.WriteLine(set1.Find("two"));

            Console.WriteLine(set1.Count);
        }
开发者ID:g-yonchev,项目名称:Data-Structures-and-Algorithms-Homework,代码行数:30,代码来源:Testing.cs

示例6: GenerateParens2

        Set<string> GenerateParens2(int remaining)
        {
		    Set<string> set = new Set<string>();
		    if (remaining == 0)
            {
			    set.Add("");
		    }
            else
            {
                Set<string> prev = GenerateParens2(remaining - 1); 
			    foreach (string str in prev)
                {
				    for (int i = 0; i < str.Length; i++)
                    {
					    if (str[i] == '(')
                        {
						    string s = InsertInside(str, i);
						    /* Add s to set if it is not already in there. Note: 	
						     * Set automatically checks for duplicates before
						     * adding, so an explicit check is not necessary. */
						    set.Add(s);			
					    }
				    }
				    set.Add("()" + str);
			    }
		    }
		    return set;
	    }
开发者ID:0x0all,项目名称:ctci,代码行数:28,代码来源:Q09_6.cs

示例7: ToSet

 internal static ISet ToSet(this IFullTextSearchResult result, String matchVar, String scoreVar)
 {
     Set s = new Set();
     if (matchVar != null) s.Add(matchVar, result.Node);
     if (scoreVar != null) s.Add(scoreVar, result.Score.ToLiteral(_factory));
     return s;
 }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:7,代码来源:FullTextExtensions.cs

示例8: Evaluate

        /// <summary>
        /// Evaluates the Select Distinct Graphs optimisation
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <returns></returns>
        public BaseMultiset Evaluate(SparqlEvaluationContext context)
        {
            context.OutputMultiset = new Multiset();
            String var;
            if (context.Query != null)
            {
                var = context.Query.Variables.First(v => v.IsResultVariable).Name;
            }
            else
            {
                var = this._graphVar;
            }

            foreach (Uri graphUri in context.Data.GraphUris)
            {
                Set s = new Set();
                if (graphUri == null)
                {
                    s.Add(var, null);
                }
                else
                {
                    s.Add(var, new UriNode(null, graphUri));
                }
                context.OutputMultiset.Add(s);
            }

            return context.OutputMultiset;
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:34,代码来源:SpecialQueryClasses.cs

示例9: Main

    static void Main(string[] args)
    {
      Set a = new Set();
      a.Add(1);
      a.Add(2);
      a.Add(3);
      Console.WriteLine("a : " + a);
      Set b = new Set();
      b.Add(2);
      b.Add(3);
      Console.WriteLine("b : " + b);
      Set c = new Set();
      c = a.Union(b);
      Console.WriteLine("a.Union(b) : " + c);
      c = a.Intersection(b);
      Console.WriteLine("a.Intersection(b) : " + c);
      c = a.Difference(b);
      Console.WriteLine("a.Difference(b) : " + c);
      bool flag;
      flag = a.IsSubsetOf(b);
      Console.WriteLine("a.IsSubsetOf(b) : " + flag);
      flag = b.IsSubsetOf(a);
      Console.WriteLine("b.IsSubsetOf(a) : " + flag);

      Console.Read();
    }
开发者ID:aponysos,项目名称:DataStructuresAndAlgorithmsInCSharp,代码行数:26,代码来源:Program.cs

示例10: AddPositiveTest

 public void AddPositiveTest()
 {
     ISet<string> sets = new Set<string>();
     sets.Add("item1");
     sets.Add("item2");
     Assert.AreEqual(2, sets.Count);
 }
开发者ID:Roman-M,项目名称:MentoringProgramm,代码行数:7,代码来源:ISetUnitTests.cs

示例11: ShouldClear

 public void ShouldClear()
 {
     var collection = new Set<string>();
     collection.Add("1");
     collection.Add("2");
     collection.Clear();
     Assert.AreEqual(0, collection.Count);
 }
开发者ID:p69,项目名称:magellan-framework,代码行数:8,代码来源:SetTests.cs

示例12: TestIfAddAddsACorrectAmount

        public void TestIfAddAddsACorrectAmount()
        {
            var set = new Set<int>();
            set.Add(5);
            set.Add(6);

            Assert.AreEqual(2, set.Count);
        }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:8,代码来源:SetTests.cs

示例13: RemoveTest

 public void RemoveTest()
 {
     Set<int> set = new Set<int>();
     set.Add(1);
     set.Add(2);
     set.Remove(1);
     Assert.IsFalse(set.Contains(1));
     Assert.IsTrue(set.Contains(2));
 }
开发者ID:Kirill-Andreev,项目名称:University,代码行数:9,代码来源:SetTest.cs

示例14: TestDel

 public void TestDel()
 {
     var mySet = new Set<int>();
     mySet.Add(1);
     mySet.Add(2);
     mySet.Del(2);
     Assert.IsTrue(mySet.IsExist(1));
     Assert.IsTrue(!mySet.IsExist(2));
 }
开发者ID:elenazab,项目名称:Homework,代码行数:9,代码来源:SetTest.cs

示例15: AddArrayToNonEmptySet

 public void AddArrayToNonEmptySet() {
    var set = new Set<int>();
    set.Add(11);
    set.Add(22);
    set.Add(new [] { 33, 44, 55 });
    Assert.Equals(5, set.Count);
    Assert.True(set.Contains(11));
    Assert.True(set.Contains(44));
 }
开发者ID:ManfredLange,项目名称:csUnit,代码行数:9,代码来源:SetTests.cs


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