Not a good implemantation, but maybe could give you hint.
public class Objx
{
private int _id;
private string _name;
private string _address;
public Objx(int id, string name, string address)
{
_id = id;
_name = name;
_address = address;
}
public int Id
{
get { return _id; }
set { _id = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Address
{
get { return _address; }
set { _address = value; }
}
public string Compare(Objx target)
{
if (this._id == target.Id)
{
var sb = new StringBuilder();
if (this._name != target.Name)
sb.AppendLine("For ID: " + this.Id + " Name changed: " + this._name);
if (this.Address != target.Address)
sb.AppendLine("For ID: " + this.Id + " Address changed: " + this.Address);
return sb.ToString();
}
return "different items";
}
}
Then;
var lstObj1 = new List<Objx>();
var obj1 = new Objx(1, "name1", "Address1");
var obj2 = new Objx(2, "name2", "Address2");
var obj3 = new Objx(3, "name3", "Address3");
lstObj1.AddRange(new List<Objx> { obj1, obj2, obj3 });
var lstObj2 = new List<Objx>();
var obj4 = new Objx(1, "name4", "Address4");
var obj5 = new Objx(5, "name5", "Address5");
var obj6 = new Objx(6, "name6", "Address6");
lstObj2.AddRange(new List<Objx> { obj4, obj5, obj6 });
var foundItems = new List<Objx>();
var sb = new StringBuilder();
foreach (var obj in lstObj2)
{
var found = lstObj1.Find(p => p.Id == obj.Id);
if (found == null)
{
sb.AppendLine("ID: " + obj.Id + " " + obj.Name + " is added.");
}
else
{
sb.AppendLine(obj.Compare(found));
foundItems.Add(found);
}
}
lstObj1.Except(foundItems).ToList().ForEach(p => sb.AppendLine("ID: " + p.Id + " " + p.Name + " removed."));
richTextBox1.AppendText(sb.ToString());