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

来源:这里教程网 时间:2026-02-21 16:16:51 作者:

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));
      }
   }
}

相关推荐