笨啦啦 2016-01-01 09:34 采纳率: 50%
浏览 1479
已采纳

C#集合问题,新手求教!

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.。这两个方法都不是静态方法啊????
  • 写回答

4条回答 默认 最新

  • threenewbee 2016-01-02 16:02
    关注

    https://msdn.microsoft.com/zh-cn/library/system.collections.collectionbase_members(v=vs.80).aspx
    List 获取一个 IList,它包含 CollectionBase 实例中元素的列表。
    看清楚了。文档说的很清楚。只怪你懒

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘