Phương thức SequenceEqual so sánh hai tập hợp theo thứ tự và giá trị từng phần tử.
Ví dụ
using System;
using System.Linq;
class Program
{
static void Main()
{
string[] arr1 = { "This", "is", "it" };
string[] arr2 = { "My", "work", "report" };
string[] arr3 = { "This", "is", "it" };
bool res1 = arr1.SequenceEqual(arr2);
Console.WriteLine(res1);
bool res2 = arr1.SequenceEqual(arr3);
Console.WriteLine(res2);
}
}
Kết quả
False True
Lưu ý: SequenceEqual so sánh tham chiếu cho kiểu tham chiếu, nhưng cho string so sánh giá trị vì string overload ==.