কম্পিউটার

ডিকশনারী. সি# এ সরান() পদ্ধতি


C# এ Dictionary.Remove() প্রপার্টি ডিকশনারী থেকে নির্দিষ্ট কী দিয়ে মান অপসারণ করতে ব্যবহৃত হয়।

সিনট্যাক্স

নিম্নলিখিত সিনট্যাক্স −

public bool Remove (TKey key);

উপরে, চাবিটি সরানোর চাবি।

উদাহরণ

ডিকশনারি. রিমুভ() প্রপার্টি −

বাস্তবায়নের জন্য এখন একটি উদাহরণ দেখি
using System;
using System.Collections.Generic;
public class Demo {
   public static void Main(){
      Dictionary<string, string> dict =
      new Dictionary<string, string>();
      dict.Add("One", "Kagido");
      dict.Add("Two", "Ngidi");
      dict.Add("Three", "Devillers");
      dict.Add("Four", "Smith");
      dict.Add("Five", "Warner");
      Console.WriteLine("Count of elements = "+dict.Count);
      Console.WriteLine("Removing some keys...");
      dict.Remove("Four");
      dict.Remove("Five");
      Console.WriteLine("Count of elements (updated) = "+dict.Count);
      Console.WriteLine("\nKey/value pairs...");
      foreach(KeyValuePair<string, string> res in dict){
         Console.WriteLine("Key = {0}, Value = {1}", res.Key, res.Value);
      }
      Console.Write("\nAll the keys..\n");
      Dictionary<string, string>.KeyCollection allKeys = dict.Keys;
      foreach(string str in allKeys){
         Console.WriteLine("Key = {0}", str);
      }
   }
}

আউটপুট

এটি নিম্নলিখিত আউটপুট −

তৈরি করবে
Count of elements = 5
Removing some keys...
Count of elements (updated) = 3
Key/value pairs...
Key = One, Value = Kagido
Key = Two, Value = Ngidi
Key = Three, Value = Devillers
All the keys..
Key = One
Key = Two
Key = Three

উদাহরণ

এখন Dictionary.Remove() পদ্ধতি −

বাস্তবায়নের জন্য আরেকটি উদাহরণ দেখা যাক
using System;
using System.Collections.Generic;
public class Demo {
   public static void Main(){
      Dictionary<string, string> dict =
      new Dictionary<string, string>();
      dict.Add("One", "Kagido");
      dict.Add("Two", "Ngidi");
      dict.Add("Three", "Devillers");
      dict.Add("Four", "Smith");
      dict.Add("Five", "Warner");
      Console.WriteLine("Count of elements = "+dict.Count);
      Console.Write("\nAll the keys..\n");
      Dictionary<string, string>.KeyCollection allKeys = dict.Keys;
      foreach(string str in allKeys){
         Console.WriteLine("Key = {0}", str);
      }
      Console.WriteLine("Removing some keys...");
      dict.Remove("Four");
      dict.Remove("Five");
      Console.WriteLine("Count of elements (updated) = "+dict.Count);
      Console.Write("\nAll the keys..updated\n");
      foreach(string str in allKeys){
         Console.WriteLine("Key = {0}", str);
      }
      Console.WriteLine("\nKey/value pairs...");
      foreach(KeyValuePair<string, string> res in dict){
         Console.WriteLine("Key = {0}, Value = {1}", res.Key, res.Value);
      }
   }
}

আউটপুট

এটি নিম্নলিখিত আউটপুট −

তৈরি করবে
Count of elements = 5
All the keys..
Key = One
Key = Two
Key = Three
Key = Four
Key = Five
Removing some keys...
Count of elements (updated) = 3
All the keys..updated
Key = One
Key = Two
Key = Three
Key/value pairs...
Key = One, Value = Kagido
Key = Two, Value = Ngidi
Key = Three, Value = Devillers

  1. C# এ ইউনিয়ন উইথ মেথড

  2. পাইথন - অভিধান থেকে একটি কী সরানোর উপায়

  3. কিভাবে একটি পাইথন অভিধান থেকে একটি কী সরাতে?

  4. কিভাবে কঙ্কাল কী সরাতে হয়