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


C# Bag.Add方法代码示例

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


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

示例1: Simple

        public void Simple()
        {
            var bag1 = new Bag<int> { 3, 4, 5, 6 };

            var bag2 = new Bag<int> { 3, 4, 5 };

            var shouldBe = new Bag<int> { 6 };

            var resultBag = bag1 - bag2;

            Assert.IsTrue(resultBag.Equals(shouldBe));

            bag1.Clear();
            bag2.Clear();

            bag1.Add(3, 3);
            bag2.Add(3, 2);

            bag1.Add(5, 5);
            bag2.Add(5, 7);

            shouldBe.Clear();
            shouldBe.Add(3, 1);

            resultBag = bag1 - bag2;

            Assert.IsTrue(resultBag.Equals(shouldBe));
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:28,代码来源:Subtract.cs

示例2: Interface

        public void Interface()
        {
            var bag1 = new Bag<int> { 3, 4, 5, 6 };

            var bag2 = new Bag<int> { 3, 4, 5 };

            var shouldBe = new Bag<int> { 6 };

            var resultBag = (Bag<int>)((IBag<int>)bag1).Subtract(bag2);

            Assert.IsTrue(resultBag.Equals(shouldBe));

            bag1.Clear();
            bag2.Clear();

            bag1.Add(3, 3);
            bag2.Add(3, 2);

            bag1.Add(5, 5);
            bag2.Add(5, 7);

            shouldBe.Clear();
            shouldBe.Add(3, 1);

            resultBag = bag1.Subtract(bag2);

            Assert.IsTrue(resultBag.Equals(shouldBe));
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:28,代码来源:Subtract.cs

示例3: Simple

        public void Simple()
        {
            var bag = new Bag<string>
                          {
                              "aa"
                          };

            Assert.AreEqual(bag.Count, 1);
            Assert.IsTrue(bag.Contains("aa"));
            Assert.AreEqual(bag["aa"], 1);

            bag.Add("bb");
            Assert.AreEqual(bag.Count, 2);
            Assert.IsTrue(bag.Contains("bb"));
            Assert.AreEqual(bag["bb"], 1);

            bag.Add("aa");
            Assert.AreEqual(bag.Count, 3);
            Assert.IsTrue(bag.Contains("aa"));
            Assert.AreEqual(bag["aa"], 2);

            bag.Add("cc", 3);
            Assert.AreEqual(bag.Count, 6);
            Assert.IsTrue(bag.Contains("cc"));
            Assert.AreEqual(bag["cc"], 3);

            bag.Add("cc", 2);

            Assert.AreEqual(bag.Count, 8);
            Assert.IsTrue(bag.Contains("cc"));
            Assert.AreEqual(bag["cc"], 5);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:32,代码来源:Add.cs

示例4: Interface

        public void Interface()
        {
            var bag1 = new Bag<string>();
            var bag2 = GetTestBag();

            var resultBag = (Bag<string>)((IBag<string>)bag1).Intersection(bag2);

            Assert.IsTrue(resultBag.Equals(bag1));

            bag1.Add("50", 2);

            var shouldBe = new Bag<string>();

            resultBag = (Bag<string>)((IBag<string>)bag1).Intersection(bag2);

            Assert.IsTrue(shouldBe.Equals(resultBag));

            bag1.Add("2", 2);

            shouldBe.Add("2", 2);

            resultBag = (Bag<string>)((IBag<string>)bag1).Intersection(bag2);

            Assert.IsTrue(shouldBe.Equals(resultBag));
        }
开发者ID:havok,项目名称:ngenerics,代码行数:25,代码来源:Intersection.cs

示例5: Simple

        public void Simple()
        {
            var bag1 = new Bag<string>();
            var bag2 = GetTestBag();

            var resultBag = bag1 * bag2;

            Assert.IsTrue(resultBag.Equals(bag1));

            bag1.Add("50", 2);

            var shouldBe = new Bag<string>();

            resultBag = bag1 * bag2;

            Assert.IsTrue(shouldBe.Equals(resultBag));

            bag1.Add("2", 2);

            shouldBe.Add("2", 2);

            resultBag = bag1 * bag2;

            Assert.IsTrue(shouldBe.Equals(resultBag));
        }
开发者ID:havok,项目名称:ngenerics,代码行数:25,代码来源:Intersection.cs

示例6: AddExample

        public void AddExample()
        {
            var bag = new Bag<string>();
            bag.Add("cat");
            bag.Add("dog");
            bag.Add("canary");

            // There should be 3 items in the bag.
            Assert.AreEqual(3, bag.Count);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:10,代码来源:BagExamples.cs

示例7: TestAdd

        public void TestAdd()
        {
            // ReSharper disable UseObjectOrCollectionInitializer
            Bag<string> target = new Bag<string>(Capacity);
            // ReSharper restore UseObjectOrCollectionInitializer
            target.Add(TestElement1);
            target.Add(TestElement2);
            target.Add(TestElement3);

            Assert.IsTrue(target.Contains(TestElement1) && target.Contains(TestElement2) && target.Contains(TestElement3));
        }
开发者ID:Kserol,项目名称:artemis_csharp-odb,代码行数:11,代码来源:TestBag.cs

示例8: CanPushSeveralItems

		public void CanPushSeveralItems()
		{
			var buffer = new byte[1024];
			var stack = new Bag(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create);
			stack.Add(1);
			stack.Add(2);
			stack.Add(3);

			Assert.Contains(3, stack);
			Assert.Contains(2, stack);
			Assert.Contains(1, stack);
		}
开发者ID:markrendle,项目名称:ravendb,代码行数:12,代码来源:BagTests.cs

示例9: AddAmountExample

        public void AddAmountExample()
        {
            var bag = new Bag<string>();
            bag.Add("cat");
            bag.Add("dog", 2);
            bag.Add("canary");

            // There are 4 items in the bag.
            Assert.AreEqual(4, bag.Count);

            // There are 2 "dog"s in the bag.
            Assert.AreEqual(2, bag["dog"]);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:13,代码来源:BagExamples.cs

示例10: CanRemove

		public void CanRemove()
		{
			var buffer = new byte[1024];
			var stack = new Bag(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create);
			stack.Add(1);
			stack.Add(2);
			stack.Add(3);
			stack.Remove(2);

			Assert.Contains(3, stack);
			Assert.DoesNotContain(2, stack);
			Assert.Contains(1, stack);
		}
开发者ID:markrendle,项目名称:ravendb,代码行数:13,代码来源:BagTests.cs

示例11: Insert

        public void Insert() {
            const int length = 30;

            // simple insert of 0 to 29
            {
                Bag<int> b = new Bag<int>();
                for (int i = 0; i < length; ++i) {
                    ((IList<int>)b).Insert(i, i);
                }

                for (int i = 0; i < length; ++i) {
                    Assert.Equal(i, b[i]);
                }
            }

            // more complex insert of 0 to 59
            {
                Bag<int> b = new Bag<int>();

                // insert even numbers
                for (int i = 0; i < length + 1; ++i) {
                    b.Add(i * 2);
                }

                // insert odd numbers
                for (int i = 0; i < length; ++i) {
                    ((IList<int>)b).Insert((i * 2) + 1, (i * 2) + 1);
                }

                // ensure it is equal
                for (int i = 0; i < length * 2; ++i) {
                    Assert.Equal(i, b[i]);
                }
            }
        }
开发者ID:jyunfan2015,项目名称:forge,代码行数:35,代码来源:BagTests.cs

示例12: CanAddToStack

		public void CanAddToStack()
		{
			var buffer = new byte[1024];
			var stack = new Bag(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create);
			stack.Add(1);

			Assert.Equal(1, stack.First());
		}
开发者ID:markrendle,项目名称:ravendb,代码行数:8,代码来源:BagTests.cs

示例13: Overloading_Shown

        private void Overloading_Shown(object sender, EventArgs e)
        {
            string lastName = "Lastname";
            int age = 21;
            float dollaz = 310.12F;
            long centz = 31012L;

            _myBag.Add(age);
            _myBag.Add(lastName);
            _myBag.Add(dollaz);
            _myBag.Add(centz);

            Bag _temporaryBag = new Bag();
            _temporaryBag.Add("Second Bag String");
            _temporaryBag.Add(100);

            _myBag += _temporaryBag;

            foreach (object contents in _myBag.Items)
            {
                outputListBox.Items.Add(contents.ToString());
            }

            Bag clonedBag;
            int itemsInClone = _myBag.Clone(out clonedBag);

            outputListBox.Items.Add("");
            foreach (object contents in clonedBag.Items)
            {
                outputListBox.Items.Add(contents.ToString());
            }

            outputListBox.Items.Add("Cloned count: " + itemsInClone);
            _myBag -= _temporaryBag;

            outputListBox.Items.Add("");
            outputListBox.Items.Add("Items in permanent bag after minus operator");
            foreach (object contents in _myBag.Items)
            {
                outputListBox.Items.Add(contents.ToString());
            }

            outputListBox.Items.Add("Count of items after minus operator: " + _myBag.Items.Count());
        }
开发者ID:etokrug,项目名称:CSharpProjects,代码行数:44,代码来源:Overloading.cs

示例14: Edges

 /// <summary>
 /// Returns all edges in this edge-weighted graph.
 /// </summary>
 /// <returns></returns>
 public Bag<Edge> Edges()
 {
     Bag<Edge> list = new Bag<Edge>();
     for (int v = 0; v < this._v; v++)
     {
         int selfLoops = 0;
         foreach (Edge e in this.Adj[v])
             if (e.Other(v) > v)
                 list.Add(e);
             else if (e.Other(v) == v)
             {
                 // only add one copy of each self loop (self loops will be consecutive)
                 if (selfLoops % 2 == 0)
                     list.Add(e);
                 selfLoops++;
             }
     }
     return list;
 }
开发者ID:qizl,项目名称:Algorithms,代码行数:23,代码来源:EdgeWeightedGraph.cs

示例15: TestBag

        /// <summary>
        /// Bag<T>
        /// A bag (multi-set) based on hash-table (WITH DUPLICATES) 
        /// Unordered collection
        /// Add / Find / Remove work in time O(1)
        /// T should provide Equals() and GetHashCode()
        /// </summary>
        private static void TestBag()
        {
            Bag<int> bagOfInts = new Bag<int>();
            bagOfInts.Add(1);
            bagOfInts.Add(1);
            bagOfInts.AddMany(new int[] { 1, 21 });
            bagOfInts.AddRepresentative(1);
            bagOfInts.ChangeNumberOfCopies(1, 3);
            Console.WriteLine("CountWhere > 2 : " + bagOfInts.CountWhere(x => x > 2));
            Console.WriteLine("Exists < 1 : " + bagOfInts.Exists(x => x < 1));
            Console.WriteLine("Copies of 1 : " + bagOfInts.NumberOfCopies(1));

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

            Bag<Student> bagOfStudents = new Bag<Student>();
        }
开发者ID:bstaykov,项目名称:Telerik-DSA,代码行数:26,代码来源:Program.cs


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