0

How to compare 2 lists in c#? 1st list data

DBvalues = [{ "_id" : ObjectId("5d98298f9110f5f13812f3c1"), "PartName" : null, "MAP" : null, "MPN" : null, "IsActive" : true, "Gtin" : "ab085347019069" }, { "_id" : ObjectId("5d98298f9110f5f13812f3c0"), "PartName" : null, "MAP" : null, "MPN" : null, "IsActive" : true, "Gtin" : "085347014064" }]

2nd list data

actualExcelvalues = [{ "_id" : ObjectId("5d98298f9110f5f13812f3c0"), "PartName" : null, "MAP" : null, "MPN" : null, "IsActive" : true, "Gtin" : "085347014064" }, { "_id" : ObjectId("5d98298f9110f5f13812f3c1"), "PartName" : null, "MAP" : null, "MPN" : null, "IsActive" : true, "Gtin" : "ab085347019069" }]

irrespective of their order/index.

2
  • What exactly do you want to compare: number and name of nodes? or node values? Commented Oct 19, 2019 at 9:40
  • To compare whether the object id(other fields also) in the 1st list is same as in the 2nd list..Same for other key and values Commented Oct 19, 2019 at 10:19

1 Answer 1

1

If you mean the strings then AreEqual works.

If you mean the objects then my technique for testing is to serialise both to indented json and compare that. Crude, but does the job.


In my current setup I have a static AreEqual<T>(T expected, T actual) which serialises both and then compares line by line to show better output when comparing fails.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.