The Wildcats record scores as rounds finish and add players as they arrive. Add appends an item; Insert places an item at a chosen position.
Use using System.Collections.Generic; at the top of the C# file, before its class definitions. Place the following statements inside an existing method.
List<int> roundGoals = new List<int>();
roundGoals.Add(2);
roundGoals.Add(0);
roundGoals.Add(2);Each Add copies one integer value into the next position. The list becomes 2, 0, 2 at indexes 0, 1, 2. Duplicate values are allowed. Add takes an item, not a destination index.
roundGoals.Insert(1, 4);The first argument is the insertion index; the second is the value. The list becomes 2, 4, 0, 2. The old items from index 1 onward shift right.
These examples use the established Player class and its public integer field NumberOfTurns.
Player jordan = new Player();
jordan.NumberOfTurns = 2;
Player casey = new Player();
casey.NumberOfTurns = 1;
List<Player> players = new List<Player>();
players.Add(jordan);
players.Insert(0, casey);Casey occupies index 0 and Jordan occupies index 1. These calls copy references into the list; neither call copies the Player object. Changing Jordan through the original variable is visible through the list as well.