bool b1 = true; int hashCode1 = b1.GetHashCode(); // Returns 1 bool b2 = false; int hashCode2 = b2.GetHashCode(); // Returns 0
DictionaryIn this example, we create a Dictionary that maps Boolean values to string values. We add two key-value pairs to the dictionary and retrieve the value associated with the true key. The Boolean.GetHashCode() method is part of the System namespace in C#.dict = new Dictionary (); dict.Add(true, "Yes"); dict.Add(false, "No"); string result = dict[true]; // Returns "Yes"