我如何比较两个通用集合?

Pen*_*uen 3 .net c# visual-studio

我如何比较两个通用集合?这是我尝试使用两个字符串数组,但它不会返回true.

namespace genericCollections
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] xx = new string[] { "gfdg", "gfgfd", "fgfgfd" };
            string[] yy = new string[] { "gfdg", "gfgfd", "fgfgfd" };
            Console.WriteLine(ComparerCollection(xx, yy).ToString());
            Console.ReadKey();
        }

        static bool ComparerCollection<T>(ICollection<T> x, ICollection<T> y)
        {
            return x.Equals(y);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Tim*_*son 8

致电Enumerable.SequenceEqual:

bool arraysAreEqual = xx.SequenceEqual(yy);
Run Code Online (Sandbox Code Playgroud)