http://www.dotnetperls.com/containskey
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
// Create Dictionary with two key value pairs.
var dictionary = new Dictionary
// Use ContainsKey method.
if (dictionary.ContainsKey("mac") == true)
{
Console.WriteLine(dictionary["mac"]); // <-- Is executed
}
// Use ContainsKey method on another string.
if (dictionary.ContainsKey("acorn"))
{
Console.WriteLine(false); // <-- Not hit
}
Console.ReadKey();
}
}
//1000

VulpesRank #55 · 29.2K reputationPosted Oct 1, 2013, 11:01 AM EDT
"mac" and 1000
"windows" and 500
The indexer, dictionary[key], returns the value for that key.
So, dictionary["mac"] returns 1000 and dictionary["windows"] would return 500.
Posted Oct 1, 2013, 11:45 AM EDT
Dror Cohen7 reputationPosted Oct 1, 2013, 11:59 AM EDT
Posted Oct 1, 2013, 12:34 PM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 1, 2013, 1:18 PM EDT
Notice though that all keys have to be unique according to the definition of equality used for the key type.
Posted Oct 2, 2013, 2:19 AM EDT
Notice though that all keys have to be unique according to the definition of equality used for the key type.
VulpesRank #55 · 29.2K reputationPosted Oct 2, 2013, 2:32 AM EDT
However, values can be duplicated. So if the value type were int, you could have two entries with a value of 500 as long as they had different keys.
Posted Oct 2, 2013, 2:37 AM EDT