What is C# analog of C++ std::pair?

前端 未结 14 2044
情话喂你
情话喂你 2020-11-29 16:54

I\'m interested: What is C#\'s analog of std::pair in C++? I found System.Web.UI.Pair class, but I\'d prefer something template-based.

Than

14条回答
  •  没有蜡笔的小新
    2020-11-29 17:28

    On order to get the above to work (I needed a pair as the key of a dictionary). I had to add:

        public override Boolean Equals(Object o)
        {
            Pair that = o as Pair;
            if (that == null)
                return false;
            else
                return this.First.Equals(that.First) && this.Second.Equals(that.Second);
        }
    

    and once I did that I also added

        public override Int32 GetHashCode()
        {
            return First.GetHashCode() ^ Second.GetHashCode();
        }
    

    to suppress a compiler warning.

提交回复
热议问题