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

CsharpProgrammingServer Side Programming

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
raja
Published on 05-Sep-2018 10:35:43
Advertisements