A dictionary is a collection of key-value pairs in C#. Dictionaries are contained in the System.Collection.Generics namespace.
The method of declaring a dictionary is as follows:
IDictionary<int, int> d = new Dictionary<int, int>();
To add elements −
IDictionary<int, int> d = new Dictionary<int, int>(); d.Add(1,97); d.Add(2,89); d.Add(3,77); d.Add(4,88);
Array stores a fixed-size sequential collection of elements of the same type . It consists of contiguous memory locations. The lowest address corresponds to the first element, and the highest address corresponds to the last element.
To define an array -
int[] arr = new int[5];
Initialize and set array elements.
int[] arr = new int[10] {3, 5, 35, 87, 56, 99, 44, 36, 78};
The above is the detailed content of What is the difference between a dictionary and an array in C#?. For more information, please follow other related articles on the PHP Chinese website!