SequenceEqual方法用于测试集合是否相等。
设置序列-
string[] arr1 = { "This", "is", "it" }; string[] arr2 = { "My", "work", "report" }; string[] arr3 = { "This", "is", "it" };
现在,使用SequenceEquals方法检查序列是否相同-
arr1.SequenceEqual(arr2);
以下是一个例子-
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); } }
输出结果
False True