fork download
  1. using System;
  2. using static System.Console;
  3. using System.Collections.Generic;
  4.  
  5. public class Program {
  6. public static void Main() {
  7. var dict = new Dictionary<Class1, int> { { new Class1 { Id = new Guid(), Name = "João" }, 0 }};
  8. foreach (var item in dict) WriteLine(item.Key.Name);
  9. }
  10. }
  11.  
  12. public class Class1 : IEquatable<Class1> {
  13. public Guid Id { get; set; }
  14. public string Name { get; set; }
  15.  
  16. public bool Equals(Class1 other) {
  17. if (ReferenceEquals(null, other)) return false;
  18. if (ReferenceEquals(this, other)) return true;
  19. return Id.Equals(other.Id) && string.Equals(Name, other.Name);
  20. }
  21.  
  22. public override bool Equals(object obj) {
  23. if (ReferenceEquals(null, obj)) return false;
  24. if (ReferenceEquals(this, obj)) return true;
  25. if (obj.GetType() != this.GetType()) return false;
  26. return Equals((Class1) obj);
  27. }
  28.  
  29. public override int GetHashCode() {
  30. unchecked {
  31. int hash = (int) 2166136261;
  32. hash = (hash * 16777619) ^ Id.GetHashCode();
  33. return hash = (hash * 16777619) ^ (Name != null ? Name.GetHashCode() : 0);
  34. }
  35. }
  36.  
  37. public static bool operator ==(Class1 left, Class1 right) => Equals(left, right);
  38.  
  39. public static bool operator !=(Class1 left, Class1 right) => !Equals(left, right);
  40. }
  41.  
  42. //https://pt.stackoverflow.com/q/191257/101
Success #stdin #stdout 0.02s 16272KB
stdin
Standard input is empty
stdout
João