Key-Value Pair

noun

say it: “KEE VAL-yoo pair” /kiː ˈvæljuː pɛr/

One entry in a dictionary: a key to look it up by and the value stored under that key.

What is Key-Value Pair in C#?

Key-Value Pair — One entry in a dictionary: a key you look things up by, and the value stored under it. Looping over a Dictionary gives you one KeyValuePair at a time, with .Key and .Value.

Dictionary<string, int> stock = new() { ["Dune"] = 4, ["Emma"] = 2 };
foreach (KeyValuePair<string, int> pair in stock)
{
    Console.WriteLine(quot;{pair.Key}: {pair.Value}");
}
// Dune: 4
// Emma: 2

In a sentence

  • “Each key-value pair in the stock dictionary holds a title and how many copies we have.”

Level: Apprentice · More C# terms at this level

Updated

In other subjects