I have to compare two lists of same class and store the difference in a string.
public class SomeCustomClass {
public int MaterialId { get; set; }
public string CwNumber { get; set; }
public string MaterialName { get; set; }
public List<MyClass1> ListMyClass { get; set; }
public SomeCustomClass() {
ListMyClass = new List<MyClass1>();
}
}
static void Main() {
SomeCustomClass a = new SomeCustomClass();
SomeCustomClass b = new SomeCustomClass();
a.CwNumber = "A";
a.MaterialId = 1;
a.MaterialName = "Material1";
a.ListMyClass.Add( new MyClass1 { id = 11,Name="John" });
a.ListMyClass.Add(new MyClass1 { id = 12, Name = "Naren" });
b.CwNumber = "A";
b.MaterialId = 2;
b.MaterialName = "Material2";
b.ListMyClass.Add(new MyClass1 { id = 11, Name = "Tamsan" });
b.ListMyClass.Add(new MyClass1 { id = 12, Name = "Naren" });
b.ListMyClass.Add(new MyClass1 { id = 13, Name = "sanjy" });
}
Now I have to compare between a.ListMyClass and b.ListMyClass and store the difference as
id = "11",
Name="John":id = 11,
Name = "Tamsan" | id = "",
Name="":id = 13,
Name = "sanjy"
The difference out put will contain -
i. Name is different for an ID.
ii. An object exists in first list but not present in 2nd list.( in that case out put string will be like id="someid",Name="somename":id="",Name="").
iii. An object present in 2nd list is not present in 1st list. (in that case out put string will be like id="",Name="":id="someid",Name="somename").