本文整理汇总了C#中Base.Count方法的典型用法代码示例。如果您正苦于以下问题:C# Base.Count方法的具体用法?C# Base.Count怎么用?C# Base.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Base
的用法示例。
在下文中一共展示了Base.Count方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpcastSet_implements_ICollection_of_Base
public void UpcastSet_implements_ICollection_of_Base()
{
ICollection<Base> upcasted = new UpCastSet<Derive, Base>();
Assert.AreEqual(false, upcasted.IsReadOnly);
Assert.AreEqual(0, upcasted.Count);
//Adds an element
var d = new Derive(1);
upcasted.Add(d);
Assert.AreEqual(1, upcasted.Count);
Assert.AreEqual(true, upcasted.Contains(d));
//CopyTo copies all elements to an array of Base
var a1 = new Base[1];
upcasted.CopyTo(a1, 0);
Assert.AreSame(d, a1[0]);
//Removes the element
upcasted.Remove(d);
Assert.AreEqual(0, upcasted.Count);
Assert.AreEqual(false, upcasted.Contains(d));
//CopyTo copies nothing after all elements are removed
var a2 = new Base[0];
upcasted.CopyTo(a2, 0);
Assert.AreEqual(0, a2.Count());
var b = new Base(1);
Assert.Throws<InvalidCastException>(() => upcasted.Add(b));
Assert.Throws<InvalidCastException>(() => upcasted.Remove(b));
}