Just to add to what FreedMalloc has said, an array or ind3exable collection like a
List<T>
containing
N
elements has valid index values from
0
to
N - 1
.
So a
List<int>
that contains three values
List<int> myNumbers = new List<int>() {10, 20, 30};
Would have three valid indexes:
0
,
1
, and
2
- any other value (positive or negative) will give you an "Index out of range" exception
Since your code explicitly uses an index of
0
, and you get an out of range exception that means your collection is empty: it has no elements so it has no valid indexes.
The solution to that is to add at least one
card
to the collection!
But ... your code seems really muddled: I have no idea what class the code you show is in, but there are two possibilities:
1) That code is part of the
card
class. If so, then it shouldn't be accessing display components like
nameText
,
costText
,
powerText
, and
descriptionText
because they are part of your form, not the card.
2) That code is part of your form. If so, then it shouldn't have card related values like
cardName
,
cost
,
power
, and
cardDescription
because they are part of the individual
card
and should be contained there rather than duplicated.
Have a think about what you are trying to do: I suspect you are a little hazy on the concept of classes and instances, as well as collections! :D