C#中如何比较两个数组?

C#中如何比较两个数组?

首先,设置要比较的两个数组 -

// two arrays
int[] arr = new int[] { 99, 87, 56, 45};
int[] brr = new int[] { 99, 87, 56, 45 };

登录后复制

现在,使用 SequenceEqual() 比较两个数组 -

arr.SequenceEqual(brr);

登录后复制

以下是比较两个数组的代码 -

示例

using System;
using System.Linq;

namespace Demo {
class Program {

static void Main(string[] args) {

// two arrays
int[] arr = new int[] { 99, 87, 56, 45};
int[] brr = new int[] { 99, 87, 56, 45 };

// compare
Console.WriteLine(arr.SequenceEqual(brr));
}
}
}

登录后复制

以上就是C#中如何比较两个数组?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!