namespace Ch11CardLib
{
class Cards:CollectionBase
{
public void Add(Card newCard)
{
List.Add(newCard);
}
public void Remove(Card newCard)
{
List.Remove(newCard);
}
public Card this[int cardIndex]
{
get
{
return (Card)List[cardIndex];
}
set
{
List[cardIndex] = value;
}
}
///
///Utility method for copying card instances into another Cards
///instance-used in Deck.shuffle(). This implementation assumes that
///source and target collections are the same size.
///
public void CopyTo(Cards targetCards)
{
for (int index = 0; index < this.Count; index++)
{
targetCards[index] = this[index];
}
}
///
///Check to see if the Cards collection contains a particular card.
///This calls the Contains() method of the ArrayList for the collection,
///which you access through the InnerList Property.
///
public bool Contains(Card card)
{
return InnerList.Contains(card);
}
}
}
這裡實現add和remove方法為什麼前面要加LIST.。這兩個方法都不是靜態方法啊????
https://msdn.microsoft.com/zh-cn/library/system.collections.collectionbase_members(v=vs.80).aspx
List 獲取一個 IList,它包含 CollectionBase 實例中元素的列表。
看清楚了。文檔說的很清楚。只怪你懶