LINQ | Equality Operator | SequenceEqual Last Updated : 22 May, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The equality operator is used to check whether the given two sequences are identically equal or not. In LINQ, the equality operation contains only one operator that is known as SequenceEqual. It is used to check whether the given elements in the sequence or collection are equal or not. If the given sequences or collections are equal then it returns true otherwise return false. It compares the value and the numbers of elements, if the collection or sequence has primitive data types. It checks the references of the objects, if the collection has complex type elements. It does not support query syntax in C# and VB.Net languages. It support method syntax in both C# and VB.Net languages. It present in both the Queryable and Enumerable class. It is implemented by using deferred execution. You are allowed to use IEqualityComparer class to compare two collections of complex type using SequenceEqual method. Example 1: CSharp // C# program to check the given // sequences are equal or not using System; using System.Linq; class GFG { static public void Main() { // Data source char[] sequence1 = {'p', 'q', 'r', 's', 'y', 'z'}; char[] sequence2 = {'p', 'q', 'r', 's', 'y', 'z'}; // Display the sequences Console.WriteLine("Sequence 1 is: "); foreach(var s1 in sequence1) { Console.WriteLine(s1); } Console.WriteLine("Sequence 2 is: "); foreach(var s2 in sequence2) { Console.WriteLine(s2); } // Check the given sequences are equal or // not Using SequenceEqual function var result = sequence1.SequenceEqual(sequence2); Console.WriteLine("Given Sequences are equal: {0}", result); } } Output: Sequence 1 is: p q r s y z Sequence 2 is: p q r s y z Given Sequences are equal: True Example 2: CSharp // C# program to check the names of // the employee are equal or not using System; using System.Linq; using System.Collections.Generic; // Employee details public class Employee1 { public int emp_id1 { get; set; } public string emp_name1 { get; set; } public string emp_lang1 { get; set; } } // Employee details public class Employee2 { public int emp_id2 { get; set; } public string emp_name2 { get; set; } public string emp_lang2 { get; set; } } public class GFG { // Main method static public void Main() { List<Employee1> emp1 = new List<Employee1>() { new Employee1() {emp_id1 = 209, emp_name1 = "Anjita", emp_lang1 = "C#"}, new Employee1() {emp_id1 = 210, emp_name1 = "Soniya", emp_lang1 = "C"}, new Employee1() {emp_id1 = 211, emp_name1 = "Rohit", emp_lang1 = "Java"}, }; List<Employee2> emp2 = new List<Employee2>() { new Employee2() {emp_id2 = 209, emp_name2 = "Anjita", emp_lang2 = "Scala"}, new Employee2() {emp_id2 = 210, emp_name2 = "Soniya", emp_lang2 = "Python"}, new Employee2() {emp_id2 = 211, emp_name2 = "Rohit", emp_lang2 = "Ruby"}, }; // Query to check the names of // the employee are equal or not // Using SequenceEqual method var res = emp1.Select(e => e.emp_name1).SequenceEqual(emp2.Select(e => e.emp_name2)); Console.WriteLine(res); } } Output: True Comment More infoAdvertise with us Next Article LINQ | Quantifier Operator | All A ankita_saini Follow Improve Article Tags : C# CSharp LINQ Similar Reads LINQ | Quantifier Operator | All In LINQ, quantifier operators are used to returning a boolean value which shows that whether some or all elements satisfies the given condition. The Standard Query Operator supports 3 different types of quantifier operators: All Any Contains All Operator The All operator is used to check each and ev 3 min read LINQ | Quantifier Operator | Any In LINQ, quantifier operators are used to returning a boolean value which shows that whether some or all elements satisfies the given condition. The Standard Query Operator supports 3 different types of quantifier operators: All Any Contains Any Operator The Any operator is used to check whether any 3 min read LINQ | Element Operator | Single The element operators are used to return a single, or a specific element from the sequence or collection. For example, in a school when we ask, who is the principal? Then there will be only one person that will be the principal of the school. So the number of students is a collection and the princip 3 min read LINQ | Set Operator | Except In LINQ, Set operators are those operators in query expression which return a result set based on the existence or non-existence of the equivalent elements within the same or different collections or sequences or sets. The standard query operator contains the following set operators: Union Intersect 3 min read LINQ | Set Operator | Except In LINQ, Set operators are those operators in query expression which return a result set based on the existence or non-existence of the equivalent elements within the same or different collections or sequences or sets. The standard query operator contains the following set operators: Union Intersect 3 min read LINQ | Quantifier Operator | Contains In LINQ, quantifier operators are used to returning a boolean value which shows that whether some or all elements satisfies the given condition. The Standard Query Operator supports 3 different types of quantifier operators: All Any Contains Contains Operator The Contains operator is used to check w 4 min read Like