这么说吧

.Net技术 码拜 9年前 (2016-03-11) 949次浏览
这么说吧  这里的targetCards[index]是不是List[cardIndex]这个,this[index]是不是value ?
public class Cards : CollectionBase
{
public void Add(Card newCard)
{
List.Add(newCard);
}
public void Remove(Card oldCard)
{
List.Remove(oldCard);
}
public Card this[int cardIndex]
{
get
{
return (Card)List[cardIndex];
}
set
{
List[cardIndex] = value;
            }
}
public void CopyTo(Cards targetCards)
{
for (int index = 0; index < this.Count; index++)
{
targetCards[index] = this[index];
            }
}
}
解决方案

20

你说的很对。
不过这个程序真有意思,用访问数组的方法去访问集合,呵呵,那list集合存在的意义何在呢?感觉这个程序像是一个C++转C#的程序员写出的东西,有点没有体会出C#语言的精髓。

15

集合类而已,去查一下c#集合类的定义就可以了
个人不太喜欢使用,不过其提供的各路接口会很方便枚举

targetCards[index]  是targetCards的List[cardIndex]
this[index]是当前类的index的value

20

你的理解是是对的。本人看了好几份代码跟你的这个都差不多。只不过类名变量名不同,都不知道谁Copy谁的了。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明这么说吧
喜欢 (0)
[1034331897@qq.com]
分享 (0)