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


C# Bag.Remove方法代码示例

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


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

示例1: Simple

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

            Assert.AreEqual(bag.Count, 6);

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

            Assert.IsTrue(bag.Remove("aa"));
            Assert.IsFalse(bag.Contains("aa"));
            Assert.AreEqual(bag["aa"], 0);
            Assert.AreEqual(bag.Count, 4);

            Assert.IsFalse(bag.Remove("dd"));
            Assert.AreEqual(bag.Count, 4);

            Assert.IsTrue(bag.Remove("bb"));
            Assert.IsFalse(bag.Contains("bb"));
            Assert.AreEqual(bag["bb"], 0);
            Assert.AreEqual(bag.Count, 3);

            Assert.IsTrue(bag.Remove("cc"));
            Assert.IsTrue(bag.Contains("cc"));
            Assert.AreEqual(bag["cc"], 2);
            Assert.AreEqual(bag.Count, 2);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:29,代码来源:Remove.cs

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

示例3: Simple

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

            Assert.IsFalse(bag1.Equals(null));

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

            bag2.Add(5);

            Assert.IsFalse(bag1.Equals(bag2));
            Assert.IsFalse(bag2.Equals(bag1));

            bag1.Add(5);

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

            // Add 6 now so that the count is the same
            bag1.Add(5);
            bag2.Add(6);
            Assert.IsFalse(bag1.Equals(bag2));
            Assert.IsFalse(bag2.Equals(bag1));

            bag1.Remove(5, 1);
            bag2.Remove(6);

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

            bag2.Add(6);

            Assert.IsFalse(bag1.Equals(bag2));
            Assert.IsFalse(bag2.Equals(bag1));

            bag1.Add(7);

            Assert.IsFalse(bag1.Equals(bag2));
            Assert.IsFalse(bag2.Equals(bag1));
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:42,代码来源:IsEqual.cs

示例4: CanRemoveAfterReopen

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

			stack = new Bag(new MemoryStream(buffer)
			{
				Position = stack.CurrentPosition.Value
			}, new MemoryStream(buffer)
			{
				Position = writer.Position
			}, StartMode.Open);

			stack.Remove(2);

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

示例5: ExceptionMaximumBelowZero

        public void ExceptionMaximumBelowZero()
        {
            var bag = new Bag<string> { "aa", "bb", "aa", { "cc", 3 } };

            bag.Remove("aa", -1);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:6,代码来源:Remove.cs

示例6: TestInventoryRemove

        public void TestInventoryRemove()
        {
            var inventory = new Bag();
            Item item1 = new Item();
            item1.Id = Guid.NewGuid();
            item1.Weight = 10;
            item1.Effects = new Effect[0];
            inventory.Add(item1);

            Item item2 = new Item();
            item2.Id = Guid.NewGuid();
            item2.Weight = 10;
            item2.Effects = new Effect[0];
            inventory.Add(item2);

            inventory.Remove(item1.Id);

            var weight = inventory.GetWeight();

            Assert.AreEqual(10, weight);
        }
开发者ID:jiowchern,项目名称:ItIsNotAGame1-Backend,代码行数:21,代码来源:UnitTest.cs

示例7: TestInventoryGetSum6

        public void TestInventoryGetSum6()
        {
            var inventory = new Bag();
            Item item1 = new Item();
            item1.Id = Guid.NewGuid();
            item1.Name = "a";
            item1.Weight = 10;
            item1.Count = 10;
            item1.Effects = new Effect[] { };
            inventory.Add(item1);

            Item item2 = new Item();
            item2.Id = Guid.NewGuid();
            item2.Name = "a";
            item2.Weight = 10;
            item2.Count = 10;
            item2.Effects = new Effect[] {  };
            inventory.Add(item2);

            inventory.Remove("a", 15);

            var amount = inventory.GetItemAmount("a");

            Assert.AreEqual(5, amount);
        }
开发者ID:jiowchern,项目名称:ItIsNotAGame1-Backend,代码行数:25,代码来源:UnitTest.cs

示例8: TestInventoryGetSum5

        public void TestInventoryGetSum5()
        {
            var inventory = new Bag();
            Item item1 = new Item();
            item1.Id = Guid.NewGuid();
            item1.Name = "a";
            item1.Weight = 10;
            item1.Count = 1;
            item1.Effects = new Effect[] { new Effect() { Type = EFFECT_TYPE.ATTACK_ADD } };
            inventory.Add(item1);

            Item item2 = new Item();
            item2.Id = Guid.NewGuid();
            item2.Name = "a";
            item2.Weight = 10;
            item2.Count = 1;
            item2.Effects = new Effect[] { new Effect() { Type = EFFECT_TYPE.ATTACK_ADD } };
            inventory.Add(item2);

            inventory.Remove("a", 2);

            var amount = inventory.GetItemAmount("a");

            Assert.AreEqual(0, amount);
        }
开发者ID:jiowchern,项目名称:ItIsNotAGame1-Backend,代码行数:25,代码来源:UnitTest.cs

示例9: TestRemove

 public void TestRemove()
 {
     Bag<string> target = new Bag<string>(Capacity) { TestElement1, TestElement2, TestElement3 };
     const int Index = 1;
     const string Expected = TestElement2;
     string actual = target.Remove(Index);
     Assert.AreEqual(Expected, actual);
 }
开发者ID:BaconSoap,项目名称:artemis_CSharp,代码行数:8,代码来源:TestBag.cs

示例10: TestNewBag

 public void TestNewBag()
 {
     Bag<string> b = new Bag<string>();
     Assert.AreEqual(0, b.Count);
     Assert.IsFalse(b.IsReadOnly);
     Assert.AreEqual(0, b.Count);
     Assert.IsFalse(b.Remove("foo"));
     Assert.IsFalse(b.Contains("bar"));
     try
     {
         b.CopyTo(new string[0], 0);
     }
     catch (Exception)
     {
         Assert.Fail("CopyTo() shouldn't touch parameter array if nothing to copy");
     }
 }
开发者ID:briandealwis,项目名称:gt,代码行数:17,代码来源:CollectionsTests.cs

示例11: TestAddAndRemove

        public void TestAddAndRemove()
        {
            Bag<string> b = new Bag<string>();
            Assert.AreEqual(0, b.Count);
            Assert.IsFalse(b.Contains("foo"));
            Assert.IsFalse(b.Contains("bar"));
            Assert.AreEqual(0, b.Occurrences("foo"));
            Assert.AreEqual(0, b.Occurrences("bar"));

            b.Add("foo");
            Assert.IsTrue(b.Contains("foo"));
            Assert.AreEqual(1, b.Count);
            Assert.AreEqual(1, b.Occurrences("foo"));
            Assert.AreEqual(0, b.Occurrences("bar"));

            b.Add("bar");
            Assert.IsTrue(b.Contains("foo"));
            Assert.IsTrue(b.Contains("bar"));
            Assert.AreEqual(2, b.Count);
            Assert.AreEqual(1, b.Occurrences("foo"));
            Assert.AreEqual(1, b.Occurrences("bar"));

            b.Add("foo");
            Assert.AreEqual(3, b.Count);
            Assert.IsTrue(b.Contains("foo"));
            Assert.IsTrue(b.Contains("bar"));
            Assert.IsFalse(b.Contains("baz"));
            Assert.AreEqual(2, b.Occurrences("foo"));
            Assert.AreEqual(1, b.Occurrences("bar"));

            Assert.IsTrue(b.Remove("foo"));
            Assert.AreEqual(2, b.Count);
            Assert.IsTrue(b.Contains("foo"));
            Assert.AreEqual(1, b.Occurrences("foo"));
            Assert.AreEqual(1, b.Occurrences("bar"));

            Assert.IsTrue(b.Remove("foo"));
            Assert.AreEqual(1, b.Count);
            Assert.IsFalse(b.Contains("foo"));
            Assert.AreEqual(0, b.Occurrences("foo"));
            Assert.AreEqual(1, b.Occurrences("bar"));

            Assert.IsFalse(b.Remove("foo"));
            Assert.AreEqual(1, b.Count);
            Assert.IsFalse(b.Contains("foo"));
            Assert.AreEqual(0, b.Occurrences("foo"));
            Assert.AreEqual(1, b.Occurrences("bar"));

            b.Clear();
            Assert.AreEqual(0, b.Count);
            Assert.IsFalse(b.Contains("foo"));
            Assert.AreEqual(0, b.Occurrences("foo"));
            Assert.AreEqual(0, b.Occurrences("bar"));
        }
开发者ID:briandealwis,项目名称:gt,代码行数:54,代码来源:CollectionsTests.cs

示例12: Main

    static void Main()
    {
        Console.Write("Bag of Integers: ");
        var bagOfInts = new Bag<int>();
        bagOfInts.Add(3);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(10);
        bagOfInts.Add(20);
        bagOfInts.Add(20);
        bagOfInts.Remove(5);
        bagOfInts.RemoveAllCopies(20);
        bagOfInts.UnionWith(new Bag<int>() { 3, 3, 4, 4, 5, 5 });
        Console.WriteLine(bagOfInts);

        Console.Write("OrderedBag of Integers: ");
        var orderedBagOfInts = new OrderedBag<int>();
        orderedBagOfInts.Add(3);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(10);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Remove(5);
        orderedBagOfInts.RemoveAllCopies(20);
        orderedBagOfInts.UnionWith(new OrderedBag<int>() { 3, 3, 4, 4, 5, 5 });
        Console.WriteLine(orderedBagOfInts);
        Console.WriteLine("Sub-range [5...10]: " +
            orderedBagOfInts.Range(5, true, 10, true));
        
        Console.Write("Set of Integers: ");
        var setOfInts = new Set<int>();
        setOfInts.Add(3);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(10);
        setOfInts.Add(20);
        setOfInts.Add(20);
        setOfInts.Remove(5);
        setOfInts.UnionWith(new Set<int>() { 3, 4, 5 });
        Console.WriteLine(setOfInts);

        Console.Write("OrderedSet of Integers: ");
        var orderedSetOfInts = new OrderedSet<int>();
        orderedSetOfInts.Add(3);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(10);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Remove(5);
        orderedSetOfInts.UnionWith(new OrderedSet<int>() { 3, 4, 5 });
        Console.WriteLine(orderedSetOfInts);
        Console.WriteLine("Sub-range [5...20): " +
            orderedSetOfInts.Range(5, true, 20, false));

        Console.Write("MultiDictionary<string,int>: ");
        var studentGrades = new MultiDictionary<string, int>(true);
        studentGrades.Add("Peter", 3);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Stanka", 5);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Tanya", 6);
        studentGrades.Add("Tanya", 4);
        Console.WriteLine(studentGrades);

        Console.WriteLine("OrderedMultiDictionary<string,int>:");
        var distancesFromSofia = new OrderedMultiDictionary<int, string>(true);
        distancesFromSofia.Add(149, "Plovdiv");
        distancesFromSofia.Add(505, "Varna");
        distancesFromSofia.Add(394, "Bourgas");
        distancesFromSofia.Add(310, "Rousse");
        distancesFromSofia.Add(163, "Pleven");
        distancesFromSofia.Add(163, "Troyan");
        foreach (var distanceTowns in distancesFromSofia)
        {
            Console.WriteLine("\t" + distanceTowns);
        }

        Console.Write("Deque<string>: ");
        var people = new Deque<string>();
        people.AddToBack("Kiro");
        people.AddToBack("Maria");
        people.AddToFront("Steve");
        people.AddManyToBack(new string[] { "Ivan", "Veronika" });
        Console.WriteLine(people);

        Console.Write("BigList<int>: ");
        var ints = new BigList<int>();
        // var ints = new List<int>();
        for (int i = 0; i < 1000000; i++)
        {
            ints.Add(i);
        }
//.........这里部分代码省略.........
开发者ID:asenAce,项目名称:Software_University_Bulgaria,代码行数:101,代码来源:PowerCollectionsDemo.cs

示例13: RemoveMaximumExample

        public void RemoveMaximumExample()
        {
            var bag = new Bag<string> {"cat", "dog", "dog", "dog", "canary"};

            // Bag contains 3 "dog"s
            Assert.AreEqual(3, bag["dog"]);

            // Remove 2 "dog"s
            bag.Remove("dog", 2);

            // Bag contains 1 "dog"
            Assert.AreEqual(1, bag["dog"]);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:13,代码来源:BagExamples.cs

示例14: RemoveExample

        public void RemoveExample()
        {
            var bag = new Bag<string> {"cat", "dog", "dog", "canary"};

            // Bag contains 2 "dog"s
            Assert.AreEqual(2, bag["dog"]);

            // Remove a "dog"
            bag.Remove("dog");

            // Bag contains 1 "dog"
            Assert.AreEqual(1, bag["dog"]);

            // Remove a "dog"
            bag.Remove("dog");

            // Bag contains 0 "dog"s
            Assert.AreEqual(0, bag["dog"]);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:19,代码来源:BagExamples.cs


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