コード例 #1
0
        /// <summary>
        /// Determines whether two spans are equal by comparing the elements by using generic Equals method
        /// </summary>
        /// <param name="first">A span of type T to compare to second.</param>
        /// <param name="second">A span of type T to compare to first.</param>
        public static bool SequenceEqual <T>(this ReadOnlySpan <T> first, ReadOnlySpan <T> second)
            where T : struct, IEquatable <T>
        {
            if (first.Length != second.Length)
            {
                return(false);
            }

            // we can not call memcmp here because structures might have nontrivial Equals implementation
            for (int i = 0; i < first.Length; i++)
            {
                if (!first.GetItemWithoutBoundariesCheck(i).Equals(second.GetItemWithoutBoundariesCheck(i)))
                {
                    return(false);
                }
            }
            return(true);
        }