An index is a special type of attribute that can be added to a class definition to provide array-like access.
Add an index to the Cards collection of the Card object:
public class Cards:CollectionBase
{
.....
public Card this[int cardIndex]
{
get{ return (Card)List[cardIndex]; }
set{ List[cardIndex]=value; }
}
}
The IList.List property returns a System.Object object;
Simple understanding: <Object>[Index] can be called only after the index is established in the class, for example:
Cards deckCards = new Cards();
....
Only when deckCards[index] is called can it be recognized by the compiler and no error will be reported.
-