C# program to check whether two sequences are the same or not


The SequenceEqual method is used to test collections for equality.

Set sequences −

string[] arr1 = { "This", "is", "it" };
string[] arr2 = { "My", "work", "report" };
string[] arr3 = { "This", "is", "it" };

Now, use the SequenceEquals methods to check whether sequences are same or not −

arr1.SequenceEqual(arr2);

The following is an example −

Example

 Live Demo

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

Output

False
True

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 22-Jun-2020

120 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements