Hi,
I have a requirement to compare two lists and figure out the differences in it.
Say, I have List<obj> objSt and List<tempobj> objTempSt, both Obj and tempObj has same definition that is something like
class Obj
{
int client_id;
string str;
decimal d;
datetime dt;
datetime curr_dt;
decimal rd;
string name;
}
class tempObj
{
int client_id;
string str;
decimal d;
datetime dt;
datetime curr_dt;
decimal rd;
string name;
}
here is the sample data for both the lists
Obj
-----
Client_id Str d dt curr_dt rd name
1 Prod 2.00 01/01/01 11/19/13 5.00 Fed
2 Prod 4.50 05/03/02 12/03/13 6.00 Kev
3 Test 6.00 06/07/07 10/02/12 4.00 Sun
tempObj
-----
Client_id Str d dt curr_dt rd name
1 Prod 2.00 01/01/01 11/19/13 5.00 Fed
2 Wen 4.50 05/03/02 07/17/10 1.00 Tom
3 Test 5.00 03/01/07 10/02/12 4.00 Sun
I need to figure out which list element is different that is Str or d or dt or curr_dt or rd or name and whats their value Prod(in first list) and Wen(in second list) and populate the values along with list elements.
Currently I am looping through the list and comparing the values
for (int i= 0; i < Obj.Count; i++)
{
if(Obj[i].Str != tempObj[i].Str)
{
Console.Writeln("Obj Str value" + Obj[i].Str + "tempObj Str value" + tempObj[i].Str);
}
if(Obj[i].d != tempObj[i].d)
{
Console.Writeln("Obj d value" + Obj[i].d + "tempObj d value" + tempObj[i].d);
}
if(Obj[i].dt != tempObj[i].dt)
{
Console.Writeln("Obj dtvalue" + Obj[i].dt+ "tempObj dt value" + tempObj[i].dt);
}
if(Obj[i].rd != tempObj[i].rd)
{
Console.Writeln("Obj rd value" + Obj[i].rd + "tempObj rd value" + tempObj[i].rd);
}
}
It is fine for few number of records but I have huge amount of List elements and data, so I was looking for other options.