笨啦啦 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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!