Пример #1
0
        /// <summary>
        /// Examine if tit and tat are equal as sequenced collections
        /// using the specified item equalityComparer (assumed compatible with the two collections).
        /// </summary>
        /// <param name="collection1">The first collection</param>
        /// <param name="collection2">The second collection</param>
        /// <param name="itemequalityComparer">The item equalityComparer to use for comparison</param>
        /// <returns>True if equal</returns>
        public static bool StaticEquals(ISequenced <T> collection1, ISequenced <T> collection2, System.Collections.Generic.IEqualityComparer <T> itemequalityComparer)
        {
            if (object.ReferenceEquals(collection1, collection2))
            {
                return(true);
            }

            if (collection1.Count != collection2.Count)
            {
                return(false);
            }

            //This way we might run through both enumerations twice, but
            //probably not (if the hash codes are good)
            if (collection1.GetSequencedHashCode() != collection2.GetSequencedHashCode())
            {
                return(false);
            }

            using (System.Collections.Generic.IEnumerator <T> dat = collection2.GetEnumerator(), dit = collection1.GetEnumerator())
            {
                while (dit.MoveNext())
                {
                    dat.MoveNext();
                    if (!itemequalityComparer.Equals(dit.Current, dat.Current))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #2
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public int GetSequencedHashCode()
 {
     return(sequenced.GetSequencedHashCode());
 }