本文整理匯總了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));
}