【发布时间】:2016-08-17 05:01:36
【问题描述】:
我是新来的,我想要一些关于 List 的帮助...
实际上,我想将我的List<x, y> 的每个y 元素添加到一个变量中。我知道,这可能很容易,但我被困在那部分了..
/// <summary>
/// Number of cards in the deck
/// </summary>
public byte NbTotalCards
{
get
{
byte nbCards = 0;
for (byte i = 0; i <= this.LstCardsWithQt.Count; i++)
{
if (this.LstCardsWithQt[i].Qt != 0)
{
if(this.LstCardsWithQt[i].Qt.Equals(2))
nbCards += 2;
else
{
nbCards += 1;
}
}
else
{
nbCards += 0;
}
}
return nbCardss;
}
}
在哪里
public List<DeckEntry> LstCardsWithQt
和
public DeckEntry(Card card, byte qt)
{
this.Card = carte;
this.Qt = qt;
}
顺便说一句,this.LstCardsWithQt[i].Qt != 0 出现错误
ArgumentOutOfRangeExeption("索引超出范围。必须是 非负且小于集合的大小")
【问题讨论】:
-
在for循环中,你应该把
-
如果项目的
Qt为 3 或更多,您确定只想将nbCards增加 1 吗?为什么是nbCards += 0;行?它没有做任何有用的事情。为什么使用Equals而不是==来比较字节? -
不是列表
。列出