Example #1
0
        /// <summary>
        /// Checks two collections to see if they contain all the same items.
        /// </summary>
        /// <typeparam name="T">Any type</typeparam>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns>
        /// True if the collections are the same length and contain the same items, in the same order.
        /// </returns>
        /// <example><code><![CDATA[
        /// var a = new int[]{ 1, 2, 3, 4, 5 };
        /// var b = new int[]{ 1, 2, 3, 4, 5 };
        /// var c = new
        /// int[]{ 1, 2, 3, 4, 6 };
        /// var d = new int[]{ 1, 2, 3, 4, 5, 6 };
        /// var e = new int[]{ 1, 2, 3, 4 };
        /// a.Matches(b); // --> true
        /// a.Matches(c); // --> false
        /// a.Matches(d); // --> false
        /// a.Matches(e); // --> false
        /// ]]></code></example>
        public static bool Matches <T>(this IEnumerable <T> a, IEnumerator b)
        {
            if (a is null && b is null)
            {
                return(true);
            }

            if ((a is null) != (b is null))
            {
                return(false);
            }

            return(a.Matches(b.AsEnumerable().Cast <T>()));
        }