Home > Backend Development > C#.Net Tutorial > How to compare two arrays in C#?

How to compare two arrays in C#?

WBOY
Release: 2023-08-27 11:57:11
forward
1250 people have browsed it

How to compare two arrays in C#?

First, set up the two arrays to be compared-

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

Now, use SequenceEqual() to compare the two arrays-

arr.SequenceEqual(brr);
Copy after login

The following is the comparison Code for two arrays -

Example

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));
      }
   }
}
Copy after login

The above is the detailed content of How to compare two arrays in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template