本文整理汇总了C#中Bag.RemoveAll方法的典型用法代码示例。如果您正苦于以下问题:C# Bag.RemoveAll方法的具体用法?C# Bag.RemoveAll怎么用?C# Bag.RemoveAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bag
的用法示例。
在下文中一共展示了Bag.RemoveAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Simple
public void Simple()
{
var bag = new Bag<string> { "aa", "bb", "aa", { "cc", 3 } };
Assert.AreEqual(bag.Count, 6);
Assert.IsTrue(bag.RemoveAll("aa"));
Assert.IsFalse(bag.Contains("aa"));
Assert.AreEqual(bag["aa"], 0);
Assert.AreEqual(bag.Count, 4);
Assert.IsFalse(bag.RemoveAll("dd"));
Assert.AreEqual(bag.Count, 4);
Assert.IsTrue(bag.RemoveAll("cc"));
Assert.IsFalse(bag.Contains("cc"));
Assert.AreEqual(bag["cc"], 0);
Assert.AreEqual(bag.Count, 1);
}
示例2: TestRemoveAll
public void TestRemoveAll()
{
Bag<string> target = new Bag<string>(Capacity) { TestElement1, TestElement2, TestElement3 };
Bag<string> bag = new Bag<string>(Capacity) { TestElement2, TestElement3 };
const bool Expected = true;
bool actual = target.RemoveAll(bag);
Assert.AreEqual(Expected, actual);
}
示例3: RemoveAllExample
public void RemoveAllExample()
{
var bag = new Bag<string> {"cat", "dog", "dog", "canary"};
// Bag contains 2 "dog"s
Assert.AreEqual(2, bag["dog"]);
// Remove "dog"
bag.RemoveAll("dog");
// Bag contains 0 "dog"
Assert.AreEqual(0, bag["dog"]);
}