的所有元素的值我是新來的,我想一些幫助列表...獲取列表<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