C# convert list to dictionary
Last modified: June 29, 2021class Population
{
public string CountryName { get; set; }
public int Count { get; set; }
}
class Program
{
static void Main(string[] args)
{
var population = new List<Population>() {
new Population { CountryName = "Hong Kong", Count = 700000 },
new Population { CountryName = "UK", Count = 6600000 } };
var dictionary = population.ToDictionary(d => d.CountryName, e => e.Count);
}
}