Lecture Topics:
ICollection
, IList
, IDictionary
(both generic and non-generic)foreach
Lab:
Generic classes allow type-safe, reusable code by parameterizing types.
Definition:
Declared with type parameters using <T>
.
Example:
public class GenericBox<T>
{
public T Item { get; set; }
public GenericBox(T item) => Item = item;
public void Display() => Console.WriteLine($"Item: {Item}");
}
GenericBox<int> intBox = new GenericBox<int>(42);
GenericBox<string> stringBox = new GenericBox<string>("Hello");
intBox.Display(); // Outputs: Item: 42
stringBox.Display(); // Outputs: Item: Hello
Key Points:
int
, string
, custom classes).List<T>
, Dictionary<TKey, TValue>
).Why This Matters: