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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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;
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0