nassss

Untitled

Mar 27th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using System;
  2.  
  3. namespace DictionaryWorkshop.Implementation
  4. {
  5. public class MyKeyValuePair<TKey, TValue>
  6. {
  7. public TKey Key { get; private set; }
  8. public TValue Value { get; set; }
  9. public MyKeyValuePair<TKey,TValue> Next { get; set; }
  10.  
  11. public MyKeyValuePair(TKey key, TValue value)
  12. {
  13. this.Key = key;
  14. this.Value = value;
  15. }
  16.  
  17. public override bool Equals(object obj)
  18. {
  19. if (obj == null)
  20. return false;
  21.  
  22. var other = obj as MyKeyValuePair<TKey, TValue>;
  23. if (other == null)
  24. return false;
  25.  
  26. return this.Key.Equals(other.Key) && this.Value.Equals(other.Value);
  27. }
  28.  
  29. public override int GetHashCode()
  30. {
  31. return this.MergeHashCode(this.Key.GetHashCode(), this.Value.GetHashCode());
  32. }
  33. private int MergeHashCode(int keyHash, int valueHash)
  34. {
  35. int hash = 5;
  36. hash = hash * 11 + keyHash.GetHashCode();
  37. hash = hash * 11 + valueHash.GetHashCode();
  38. return hash;
  39. }
  40. public override string ToString()
  41. {
  42. return $"{this.Key}" + $"{this.Value}";
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment