Here iam trying to compare two lists which is of same type (AddressList) as given below.
Below is a generic method to compare two lists which i got from one web site
If I pass a List<string> or List<int> to the below method it works fine.
But if iam trying to pass an user defined list its not allowing...
I want to compare each value in one list with another..
Please could you help me out here
AddressList
HouseName
StreetName
PinCode
bool isEqual = IsEqual(addressList1,addressList2, Comparer<AddressList>.Default);
public static bool IsEqual<T>(IList<T> sourceList, IList<T> targetList, IComparer<T> comparer) where T : IComparable<T>
{
if (sourceList.Count != targetList.Count)
{
return false;
}
int index = 0;
while (index < sourceList.Count &&
comparer.Compare(sourceList[index], targetList[index]) == 0)
{
index++;
}
if (index != sourceList.Count)
{
return false;
}
return true;
}