Repository: dotnet/runtime
File: src/libraries/System.Collections.Immutable/src/System/Linq/ImmutableArrayExtensions.cs (C#)

Code before:
            {
                if (!comparer.Equals(immutableArray.array![i], items.array![i]))
                {
                    return false;
                }
            }

            return true;
        }

        /// <summary>
        /// Determines whether two sequences are equal according to an equality comparer.
        /// </summary>
        /// <typeparam name="TDerived">The type of element in the compared array.</typeparam>
        /// <typeparam name="TBase">The type of element contained by the collection.</typeparam>
        public static bool SequenceEqual<TDerived, TBase>(this ImmutableArray<TBase> immutableArray, IEnumerable<TDerived> items, IEqualityComparer<TBase>? comparer = null) where TDerived : TBase
        {
            if (items is ICollection<TBase> itemsCol)
            {
                immutableArray.ThrowNullRefIfNotInitialized();
                return immutableArray.array!.SequenceEqual(itemsCol, comparer);
            }

            return Impl(immutableArray, items, comparer);

            static bool Impl(ImmutableArray<TBase> immutableArray, IEnumerable<TDerived> items, IEqualityComparer<TBase>? comparer)
            {
                Requires.NotNull(items, nameof(items));

                comparer ??= EqualityComparer<TBase>.Default;

                int i = 0;
                int n = immutableArray.Length;
                foreach (TDerived item in items)
                {
                    if (i == n)
                    {
                        return false;
                    }

                    if (!comparer.Equals(immutableArray[i], item))
                    {
                        return false;
                    }

                    i++;
                }

                return i == n;
            }
        }

Review comment (suggestion):
I think you can change the type of the `items` parameter here to `IEnumerable<TBase>` and cast at the call site. Let's see what other reviewers think. 

Code after:
            {
                if (!comparer.Equals(immutableArray.array[i], items.array[i]))
                {
                    return false;
                }
            }

            return true;
        }

        /// <summary>
        /// Determines whether two sequences are equal according to an equality comparer.
        /// </summary>
        /// <typeparam name="TDerived">The type of element in the compared array.</typeparam>
        /// <typeparam name="TBase">The type of element contained by the collection.</typeparam>
        public static bool SequenceEqual<TDerived, TBase>(this ImmutableArray<TBase> immutableArray, IEnumerable<TDerived> items, IEqualityComparer<TBase>? comparer = null) where TDerived : TBase
        {
            if (items is ICollection<TBase> itemsCol)
            {
                immutableArray.ThrowNullRefIfNotInitialized();
                return Enumerable.SequenceEqual(immutableArray.array, itemsCol, comparer);
            }

            return Enumerate(immutableArray, items, comparer);

            static bool Enumerate(ImmutableArray<TBase> immutableArray, IEnumerable<TDerived> items, IEqualityComparer<TBase>? comparer)
            {
                Requires.NotNull(items, nameof(items));

                comparer ??= EqualityComparer<TBase>.Default;

                int i = 0;
                int n = immutableArray.Length;
                foreach (TDerived item in items)
                {
                    if (i == n)
                    {
                        return false;
                    }

                    if (!comparer.Equals(immutableArray[i], item))
                    {
                        return false;
                    }

                    i++;
                }

                return i == n;
            }
        }