Dictionary<TKey, TValue>.ContainsKey(key) মেথড নির্দিষ্ট কী ডিকশনারিতে আছে কিনা চেক করে (O(1))।
উদাহরণ
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
Dictionary d = new Dictionary()
{
{1, "Electronics"},
{2, "Clothing"},
{3, "Toys"},
{4, "Footwear"},
{5, "Accessories"}
};
foreach (KeyValuePair ele in d)
Console.WriteLine("Key = {0}, Value = {1}", ele.Key, ele.Value);
Console.WriteLine("Key 5 exists? " + d.ContainsKey(5));
}
}
আউটপুট
Key = 1, Value = Electronics Key = 2, Value = Clothing Key = 3, Value = Toys Key = 4, Value = Footwear Key = 5, Value = Accessories Key 5 exists? True
TryGetValue ব্যবহার করলে একই সময় কী চেক এবং মান পাওয়া যায় (দক্ষতর)।