You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$10
For Premium members:
This article will demonstrate the comparison of the objects (or list of objects) with n level down list comparison.
Introduction
In my previous article, the object comparison was made capable only for 1 level down list object. This article will demonstrate the comparison of the objects (or list of objects) with n level down list comparison. You can have any class that contains the list property, that can contain the further list properties, and so on.
We are going to compare two objects of the same class having collection property as List or multiple collection properties with N level.
Comparision can be done on the following basis.
NoteObjects can contain the list properties. These lists can contain further list properties and so on. Our main aim is to compare the objects with multiple levels of list properties.ImplementationCreate a console application (say CompareObject) in C# using Visual Studio and add classes as below. You can create these as a separate file also.
In the above class, the List<Department> property is defined that leads to further list property in term of List<Block>. So, the situation can be - this Block can also have list properties and so on.
Add the static class ObjectCompare.cs
This class contains two static methods ( CompareList and Compare ). The first method is responsible for comparing the two List Objects and the second will compare the two given objects of the same class.
Modify the Main method of class/file Program.cs
In the below demonstration, we have created the People object and created the list of people objects. We have done comparison on the List of objects and also the comparison on individual objects.
Below is the output screen for the given application.
The SOLID Principles