কম্পিউটার

C# এ একটি হ্যাশটেবলের নির্দিষ্ট কীটির জন্য হ্যাশ কোড কীভাবে পাবেন?


হ্যাশটেবলের নির্দিষ্ট কীটির জন্য হ্যাশ কোড পেতে, কোডটি নিম্নরূপ -

উদাহরণ

using System;
using System.Collections;
public class HashCode : Hashtable {
   public static void Main(string[] args) {
      HashCode hash = new HashCode();
      hash.Add("A", "Jacob");
      hash.Add("B", "Mark");
      hash.Add("C", "Tom");
      hash.Add("D", "Nathan");
      hash.Add("E", "Tim");
      hash.Add("F", "John");
      hash.Add("G", "Gary");
      Console.WriteLine("Key and Value pairs...");
      foreach(DictionaryEntry entry in hash) {
         Console.WriteLine("{0} and {1} ", entry.Key, entry.Value);
      }
      Console.Write("HashCode for key D =" + (hash.GetHash("D")) );
   }
}

আউটপুট

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

তৈরি করবে
Key and Value pairs...
G and Gary
A and Jacob
B and Mark
C and Tom
D and Nathan
E and Tim
F and John
HashCode for key D =-842352676

উদাহরণ

আসুন আরেকটি উদাহরণ দেখি -

using System;
using System.Collections;
public class HashCode : Hashtable {
   public static void Main(string[] args) {
      HashCode hash = new HashCode();
      hash.Add('1', "One");
      hash.Add('2', "Two");
      hash.Add('3', "Three");
      hash.Add('4', "Four");
      Console.WriteLine("Key and Value pairs...");
      foreach(DictionaryEntry entry in hash) {
         Console.WriteLine("{0} and {1} ", entry.Key, entry.Value);
      }
      Console.WriteLine("HashCode for key 1 = " + (hash.GetHash('1')));
      Console.WriteLine("HashCode for key 2 = " + (hash.GetHash('2')));
      Console.WriteLine("HashCode for key 3 = " + (hash.GetHash('3')));
      Console.WriteLine("HashCode for key 4 = " + (hash.GetHash('4')));
   }
}

আউটপুট

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

তৈরি করবে
Key and Value pairs...
3 and Three
2 and Two
4 and Four
1 and One
HashCode for key 1 = 3211313
HashCode for key 2 = 3276850
HashCode for key 3 = 3342387
HashCode for key 4 = 3407924

  1. C# এ হ্যাশটেবল থেকে নির্দিষ্ট কী দিয়ে উপাদানটি সরান

  2. C# এ হ্যাশটেবলের মাধ্যমে পুনরাবৃত্তি করে এমন একটি গণনাকারী পান

  3. C# এ বর্তমান Int64 উদাহরণের জন্য হ্যাশ কোড পান

  4. হ্যাশটেবলে C# এ একটি নির্দিষ্ট কী রয়েছে কিনা তা পরীক্ষা করুন