Home > Article > Backend Development > What is the difference between a list and a dictionary in C#?
A dictionary is a collection of keys and values in C#. Dictionary
List collection is a generic class that can store any data type to create a list.
A list is a set of items -List<string> myList = new List<string>() { "Maths", "English", " Science" };
A dictionary is a set of key-value pairs.
Dictionary<string, int> d = new Dictionary<string, int>(); d.Add("squash", 1); d.Add("football", 2); d.Add("rugby", 3);
Looping through lists is easier and faster, and elements can be accessed easily using indexes through the list.
The above is the detailed content of What is the difference between a list and a dictionary in C#?. For more information, please follow other related articles on the PHP Chinese website!