C#-এ HybridDictionary ক্লাসের Remove(object key) মেথড ব্যবহার করে নির্দিষ্ট কী-এর এন্ট্রি মুছে ফেলা যায়। HybridDictionary ছোট ডেটার জন্য ListDictionary এবং বড় ডেটার জন্য Hashtable এর মধ্যে অটোমেটিক্যালি স্যুইচ করে। Remove মেথড কী পেলে এন্ট্রিটি মুছে ফেলে এবং সফল হলে কিছু রিটার্ন করে না (void)।
উদাহরণ ১: "3" কী-এর এন্ট্রি মুছে ফেলা
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
HybridDictionary dict1 = new HybridDictionary();
dict1.Add("A", "Books");
dict1.Add("B", "Electronics");
dict1.Add("C", "Smart Wearables");
dict1.Add("D", "Pet Supplies");
dict1.Add("E", "Clothing");
dict1.Add("F", "Footwear");
Console.WriteLine("HybridDictionary1 উপাদান...");
foreach (DictionaryEntry d in dict1) {
Console.WriteLine(d.Key + " " + d.Value);
}
HybridDictionary dict2 = new HybridDictionary();
dict2.Add("1", "One");
dict2.Add("2", "Two");
dict2.Add("3", "Three");
dict2.Add("4", "Four");
dict2.Add("5", "Five");
dict2.Add("6", "Six");
Console.WriteLine("\nHybridDictionary2 কী-মান জোড়া...");
IDictionaryEnumerator demoEnum = dict2.GetEnumerator();
while (demoEnum.MoveNext()) {
Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
}
// "3" কী মুছে ফেলা
dict2.Remove("3");
Console.WriteLine("\nHybridDictionary2 কী-মান জোড়া... (আপডেটেড)");
demoEnum = dict2.GetEnumerator();
while (demoEnum.MoveNext()) {
Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
}
}
}
আউটপুট
HybridDictionary1 উপাদান... A Books B Electronics C Smart Wearables D Pet Supplies E Clothing F Footwear HybridDictionary2 কী-মান জোড়া... Key = 1, Value = One Key = 2, Value = Two Key = 3, Value = Three Key = 4, Value = Four Key = 5, Value = Five Key = 6, Value = Six HybridDictionary2 কী-মান জোড়া... (আপডেটেড) Key = 1, Value = One Key = 2, Value = Two Key = 4, Value = Four Key = 5, Value = Five Key = 6, Value = Six
উদাহরণ ২: একাধিক কী মুছে ফেলা
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
HybridDictionary dict = new HybridDictionary();
dict.Add("1", "Marketing");
dict.Add("2", "Purchase");
dict.Add("3", "Sales");
dict.Add("4", "IT");
dict.Add("5", "Finance");
dict.Add("6", "Operations");
Console.WriteLine("HybridDictionary কী-মান জোড়া...");
IDictionaryEnumerator demoEnum = dict.GetEnumerator();
while (demoEnum.MoveNext()) {
Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
}
dict.Remove("3");
Console.WriteLine("\nHybridDictionary কী-মান জোড়া... (আপডেটেড)");
demoEnum = dict.GetEnumerator();
while (demoEnum.MoveNext()) {
Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
}
dict.Remove("4");
Console.WriteLine("\nHybridDictionary কী-মান জোড়া... (আপডেটেড)");
demoEnum = dict.GetEnumerator();
while (demoEnum.MoveNext()) {
Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
}
}
}
আউটপুট
HybridDictionary কী-মান জোড়া... Key = 1, Value = Marketing Key = 2, Value = Purchase Key = 3, Value = Sales Key = 4, Value = IT Key = 5, Value = Finance Key = 6, Value = Operations HybridDictionary কী-মান জোড়া... (আপডেটেড) Key = 1, Value = Marketing Key = 2, Value = Purchase Key = 4, Value = IT Key = 5, Value = Finance Key = 6, Value = Operations HybridDictionary কী-মান জোড়া... (আপডেটেড) Key = 1, Value = Marketing Key = 2, Value = Purchase Key = 5, Value = Finance Key = 6, Value = Operations
ব্যাখ্যা: Remove(key) মেথড কী খুঁজে পেলে সংশ্লিষ্ট এন্ট্রিটি মুছে ফেলে। কী না পেলে কিছুই করে না (এক্সেপশন থ্রো করে না)। HybridDictionary ইনসারশন অর্ডার বজায় রাখে না। এটি IDictionary ইমপ্লিমেন্ট করে। পারফরম্যান্স: ছোট সাইজে O(n), বড় সাইজে O(1) গড়। লিগ্যাসি ক্লাস হওয়ায় নতুন প্রজেক্টে Dictionary<TKey, TValue> প্রিয়।