ContainsKey() মেথড চেক করে যে ডিকশনারিতে নির্দিষ্ট কী আছে কিনা। এটি বুলিয়ান রিটার্ন করে।
উদাহরণ
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
var dict = new Dictionary {
{ "TV", 1 },
{ "Home Theatre", 2 },
{ "Amazon Alexa", 3 },
{ "Google Home", 5 },
{ "Laptop", 5 },
{ "Bluetooth Speaker", 6 }
};
if (dict.ContainsKey("Laptop")) {
Console.WriteLine(dict["Laptop"]); // 5
}
if (dict.ContainsKey("Amazon Alexa")) {
Console.WriteLine(dict["Amazon Alexa"]); // 3
}
}
}
আউটপুট
5 3