Overriding Equals (without overriding GetHashCode() ) is a bad idea, and introduces a lot of complexity Listx. Id == item.Id ); Console. WriteLine(isInSecondList); } If you are doing lots of this, or the lists are long - you may benefit from building a hash-set of the known ids first (again, a C# example - sorry): var ids = new HashSet(list2.
Select(x => x.Id)); foreach (ClassB item in list1) { bool isInSecondList = ids. Contains(item. Id); Console.
WriteLine(isInSecondList); } This has the initial cost of hashing all the data, but may be significantly faster overall.
Overriding Equals (without overriding GetHashCode()) is a bad idea, and introduces a lot of complexity. List doesn't allow you to pass in a custom IEqualityComparer, so IMO you should check it manually (foreach etc). Or in .
NET 3.5, LINQ; I'll give a C# example (VB isn't my strong point): foreach (ClassB item in list1) { bool isInSecondList = list2. Any( x=>x.Id == item. Id ); Console.
WriteLine(isInSecondList); } If you are doing lots of this, or the lists are long - you may benefit from building a hash-set of the known ids first (again, a C# example - sorry): var ids = new HashSet(list2. Select(x => x. Id)); foreach (ClassB item in list1) { bool isInSecondList = ids.
Contains(item.Id); Console. WriteLine(isInSecondList); } This has the initial cost of hashing all the data, but may be significantly faster overall.
I would like some feedback on how we can best write a generic function that will enable two Lists to be compared. The Lists contain class objects and we would like to iterate through one list, looking for the same item in a second List and report any differences. We already have a method to compare classes, so we need feedback on how we can feed the method (shown below) from two Lists.
For example, say we have a simple "Employee" class that has three properties, Name, ID, Department. We want to report the differences between List and another List. Both lists will always contain the same number of items.
As mentioned above, we have a generic method that we use to compare two classes, how can we incorporate this method to cater for Lists, i.e. Any suggestions or ideas appreciated? NET 2.0 so LINQ is out of the question.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.