Hi,
I have two sorted list :
SortedList list1 = new SortedList();
SortedList list2 = new SortedList();
list1.Add("A",2);
list1.Add("B", 4);
list1.Add("C",4);
list1.Add("D", 6);
list1.Add("E",5);
list2.Add("A", 2);
list2.Add("B", 4);
list2.Add("C", 4);
list2.Add("D", 5);
list2.Add("E", 5);
I want to check the following :
1. List1 has all the keys in list2.
2. The value of the key in List1should be less than or equal to values of the same key in list2. If not, the loop should break and tell which key had mismatch value. For eg: the key "D" in list1 has a value that is greater than the key "D" in list2. So there should be an error telling that key "D" has mismatch.
Please support your answer with code.
thanks.
this is pretty easy...simply compare a to b add icomparable as an interface and extend it as you wish...similar to extending a sort function of a sorted list to a custom sort...asking for a solution via code is a bit much ...do a quick search on icomparable and you will be able to do this with ease.
You could always do a for each loop and use the indexer for both and compare them, sending erroneous values to a logfile or a contruct of your choice.
ps: for each is effective to abotu 50000 iterations after that there are other ways to compare that are better.
Let me know if you have issues with this.
jo?l Hébert
Anyone who could write some code..i searched icomparable but hpow to use it? have just started with .net :(
#Region "Functions"
Public Function SortNodeArrayList(ByVal nodeList As XmlNodeList, ByVal language As Char) As System.Collections.ArrayList
Dim list As New System.Collections.ArrayList
For Each node As XmlElement In nodeList
list.Add(node)
Next
list.Sort(New CompareParsedDates)
Return list
End Function
#End Region
#Region "Helper Classes"
Public Class CompareParsedDates
Implements IComparer
Public Overridable Overloads Function Compare(ByVal value1 As Object, ByVal value2 As Object) As Integer Implements IComparer.Compare
Dim Date1 As DateTime = Date.Parse(value1.Item("year_e").InnerText & "-" & value1.Item("month_e").InnerText & "-" & value1.Item("day_e").InnerText)
Dim Date2 As DateTime = Date.Parse(value2.Item("year_e").InnerText & "-" & value2.Item("month_e").InnerText & "-" & value2.Item("day_e").InnerText)
Return DateDiff(DateInterval.Day, Date1, Date2)
End Function
End Class
#End Region
0 comments:
Post a Comment