本文整理汇总了C#中Bag.Occurrences方法的典型用法代码示例。如果您正苦于以下问题:C# Bag.Occurrences方法的具体用法?C# Bag.Occurrences怎么用?C# Bag.Occurrences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bag
的用法示例。
在下文中一共展示了Bag.Occurrences方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ElemsToStr
private static string ElemsToStr(Bag<TypeDescriptor> elems)
{
var sb = new StringBuilder();
if (elems != null)
{
foreach (var e in elems.AsSet())
sb.Append("(" + e + ":" + elems.Occurrences(e) + ")");
}
return sb.ToString();
}
示例2: 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"));
}