[C#] How to use custom object as dictionary key?

  public class User
    {
        public string UserId { get; set; }
        public string UserName { get; set; }


        public bool Equals(User user) => user.UserId.Equals(UserId);
        public override bool Equals(object o) => Equals(o as User);

        public override int GetHashCode() => UserId.GetHashCode();

    }

Ref:

How to use custom object as dictionary key?

原文地址:https://www.cnblogs.com/zhonglinchen/p/14411345.html