的所有元素的值我是新来的,我想一些帮助列表...获取列表<x, y>
其实,我想我的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循环中,应将<=更改为<,因为它只有Count元素。 – hazjack
如果一件物品的“Qt”是3或更多,你确定只想增加'nbCards' 1吗?为什么'nbCards + = 0;'行?它没有做任何有用的事情。为什么使用'Equals'来比较字节而不是'=='? –
不是列表。列表 –
Paparazzi