Lists

  • Not required to specify the size

  • All of the below are valid:

List<int> list1 = new List<int>();
List<int> list2 = new List<int>(3);
List<int> list3 = new List<int>() { 11, 22, 33 };
List<int> list4 = new List<int>(3) { 11, 22 };
List<int> list5 = new List<int>(3) { 11, 22, 33, 44 };

Data input/retrieval

List<int> list = new List<int>() { 11, 22, 33 };
// List: 11, 22, 33

list.Add(44);
// List: 11, 22, 33, 44

int first = list[0];
int last = list[list.Count - 1];

list.RemoveAt(0);
// List: 22, 33, 44

Last updated