C#程序检查两个序列是否相同
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);
}
}
输出结果
FalseTrue
以上是 C#程序检查两个序列是否相同 的全部内容, 来源链接: utcz.com/z/322090.html