The SequenceEqual method is used to compare two collections or lists of elements sequences that are equal or not. It compares two elements pair-wise and sees elements that are matched are not. It returns the Boolean value.
Syntax
collection1.SequenceEqual( collection2);
Example
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
List<string> count1= new List<string>() { 'UK', 'Australia', 'India', 'USA' };
List<string> count2 = new List<string>() { 'India', 'UAE', 'Canada', 'UK', 'China', 'Pok' };
bool flag = count1.SequenceEqual(count2);
Console.WriteLine('List are {0} same ', !flag ? 'not' : '');
List<string> count3= new List<string>() { 'UK', 'Australia', 'India', 'USA' };
List<string> count4 = new List<string>() { 'UK', 'Australia', 'India', 'USA'};
bool flag1 = count3.SequenceEqual(count4);
Console.WriteLine('List are {0}same ', !flag1 ? 'not ' : '');
Console.ReadLine();
}
}
Output
List are not same List are same
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
The SequenceEqual method is used to compare two collections or lists of elements sequences that are equal or not. It compares two elements pair-wise and sees elements that are matched are not. It returns the Boolean value.
Syntax
Example
using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { List<string> count1= new List<string>() { 'UK', 'Australia', 'India', 'USA' }; List<string> count2 = new List<string>() { 'India', 'UAE', 'Canada', 'UK', 'China', 'Pok' }; bool flag = count1.SequenceEqual(count2); Console.WriteLine('List are {0} same ', !flag ? 'not' : ''); List<string> count3= new List<string>() { 'UK', 'Australia', 'India', 'USA' }; List<string> count4 = new List<string>() { 'UK', 'Australia', 'India', 'USA'}; bool flag1 = count3.SequenceEqual(count4); Console.WriteLine('List are {0}same ', !flag1 ? 'not ' : ''); Console.ReadLine(); } }Output