Reputation: 85
Hi i'm working on a project written in c# webform and it requere loghistory of changes if some one updated the data i should be inserted to logs table but i need to capture which column or which field is being update. so i think comparing 2 list the oldList before update and the list after update if i have this class
public myClass class{
public string col1{get; set;}
public string col2{get; set;}
public string col3{get; set;}
}
and list like this with datas
List<myClass > old = new List<myClass >();
List<myClass > new = new List<myClass >();
how can i compire this 2 and get the column and the old and new data of the difference with out using Linq because the application is a existing and uses .net 2.0 framework so i belive Linq is not availavle yet in this.
I'm not requered to update the framwork for some reason.
Upvotes: 0
Views: 93
Reputation: 54
Implement IComparable interface in your class
public class myclass : IComparable<myclass>
{
public string col1 { get; set; }
public string col2 { get; set; }
public string col3 { get; set; }
public int CompareTo(myclass obj)
{
return this.col1.CompareTo(obj.col1);
}
}
Then sort your list and iterate through it
oldlist.Sort();
newlist.Sort();
for (int i = 0; i < oldlist.Count; i++)
{
string oldcol1 = oldlist[i].col1;
string newcol1 = newlist[i].col1;
}
Upvotes: 1