using System; using System.Collections.Generic; using System.Text; namespace QiHe.CodeLib { /// /// Pair /// /// The type of the left. /// The type of the right. public class Pair : IEquatable> { /// /// /// public TLeft Left; /// /// /// public TRight Right; /// /// Initializes a new instance of the class. /// /// The left. /// The right. public Pair(TLeft left, TRight right) { Left = left; Right = right; } /// /// Returns a that represents the current . /// /// /// A that represents the current . /// public override string ToString() { return string.Format("({0},{1})", Left, Right); } /// /// Serves as a hash function for a particular type. is suitable for use in hashing algorithms and data structures like a hash table. /// /// /// A hash code for the current . /// public override int GetHashCode() { return Left.GetHashCode() + Right.GetHashCode(); } /// /// Determines whether the specified is equal to the current . /// /// The to compare with the current . /// /// true if the specified is equal to the current ; otherwise, false. /// public override bool Equals(object obj) { if (obj is Pair) { return this.Equals((Pair)obj); } else { return false; } } /// /// Indicates whether the current object is equal to another object of the same type. /// /// An object to compare with this object. /// /// true if the current object is equal to the other parameter; otherwise, false. /// public bool Equals(Pair other) { return this.Left.Equals(other.Left) && this.Right.Equals(other.Right); } /// /// Implements the operator ==. /// /// The one. /// The other. /// The result of the operator. public static bool operator ==(Pair one, Pair other) { return one.Equals(other); } /// /// Implements the operator !=. /// /// The one. /// The other. /// The result of the operator. public static bool operator !=(Pair one, Pair other) { return !(one == other); } } }