Mid Collections

How do you add elements to a List<T> in C#?

You can use the Add() or AddRange() method.

Example:

Follow:

List<int> numbers = new List<int>();

numbers.Add(10); // Add single item

numbers.AddRange(new int[] { 20, 30 }); // Add multiple

More from C# Programming Tutorial

All questions for this course