Ejemplo n.º 1
0
        /// <summary>
        /// Compares the UOPair to the other UOPair and returns an indication of their relative values (based on the ICompare of their elements).
        /// </summary>
        /// <param name="other">the UOPair to compare to</param>
        /// <returns></returns>
        public int CompareTo(UOPair <T> other)
        {
            //If we are the same object in memory, we are equal
            if ((object)this == (object)other)
            {
                return(0);
            }

            //If our hash codes are different, sort on it
            int hashCodeComp = GetHashCode().CompareTo(other.GetHashCode());

            if (0 != hashCodeComp)
            {
                return(hashCodeComp);
            }


            int compFirst = ((IComparable)First).CompareTo((IComparable)other.First);

            if (compFirst != 0)
            {
                return(compFirst);
            }

            return(((IComparable)Second).CompareTo((IComparable)other.Second));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Two UOPairs are equal if their (sorted) elements are equal.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (!(obj is UOPair <T>))
            {
                return(false);
            }

            UOPair <T> other = (UOPair <T>)obj;

            return(First.Equals(other.First) && Second.Equals(other.Second));
        }