How to check the Equality of Anonymous Types in C#?

The Equals method is used to check the equality. The anonymous types will be equal of it has the same order, type, name and values.

How to check the Equality of Anonymous Types in C#?

Below is a sample sourcecode demonstrating how to check the Equality of Anonymous types in c#.

using System;

using System.Collections.Generic;

using System.Data;

using System.Linq;

namespace AbundantCode

{

internal class Program

{

//Using block for SQLConnection in C#

private static void Main(string[] args)

{

var Employee1 = new { Name = "Martin", Designation = "Chief Architect" };

var Employee2 = new { Name = "Peter", Designation = "Senior Software Egineer" };

var Employee3 = new { Name = "Kamal", Designation = "Trainee", DOJ = "1/10/2013" };

var Employee4 = new { Name = "Martin", Designation = "Chief Architect" };

Console.WriteLine(Employee1.Equals(Employee4));

Console.WriteLine(Employee1.Equals(Employee2));

Console.WriteLine(Employee1.Equals(Employee3));

Console.ReadLine();

}

}

}
How to check the Equality of Anonymous Types in C#?