Simple, Quality, Awesome Software

Generics Quiz

Below are the answers to the Generics Quiz, along with a brief discussion.

1. Generics allow you to create classes that are type safe, without needing to commit to specific types in the declaration.

2. List strings = new List();

3. Two. One generic type parameter is for the key, and a second is for the value.

4. False. Generic classes can have any number of generic type parameters.

5. The Add(T newItem) method.

6. Both Clear() and RemoveAt(int index) remove items from a List. The first removes everything, the second removes the item at a specific index.