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
VulpesPosted Oct 1, 2013, 3:01 PM
"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 2, 2013, 6:37 AM
VulpesPosted Oct 2, 2013, 6:32 AM
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, 6:19 AM
Notice though that all keys have to be unique according to the definition of equality used for the key type.
VulpesPosted Oct 1, 2013, 5:18 PM
Notice though that all keys have to be unique according to the definition of equality used for the key type.
Posted Oct 1, 2013, 4:34 PM
Dror CohenPosted Oct 1, 2013, 3:59 PM
Posted Oct 1, 2013, 3:45 PM