How can you maintain the Uniqueness of a Key in a Dictionary<T, int>()?

  • Technically a Dictionary requires its Keys to be unique.
  • Dictionary also uses Hashing on the Keys to ensure access to a particular key can happen in constant time.
  • If there is a complex Type (such as a custom class) we can override the GetHashCode() and Equals() method which the Dictionary internally uses to set the Key, and how two Keys can be compared while lookup.

Can you add a ComplexType as a Key in a Dictionary<T, int>()?

C# Concepts Posted May 14, 2021

You can now show your support. 😊

We use cookies to provide you with a great user experience, analyze traffic and serve targeted promotions.   Learn More   Accept