Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Help with comparing lists using IComparable

$
0
0

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;
        }

 


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>