views:

42

answers:

2

Hello,

How can I check a new KeyValuePair against an existing list of KeyValuePair ? I want to compare for a condition to include or exclude the item. I am using vb.net 3.5

it is a nested For loop and I am deleting a datarow on the result of the condition

args = (existing list of KeyValuePAir)
For Each datarow As DataRow In ds.Tables(0).Rows
Dim args2 As KeyValuePair(Of Integer, Integer) = New KeyValuePair(Of Integer, Integer)(datarow.Item("Integer1"), datarow.Item("Integer2"))

what I want to do here is see if args2 is already contained in args if not I would delete the datarow , but I also need to search the datarow multiple times

A: 

Try

For Each pair As KeyValuePair In pairs 
    If pair.Key == myPair.Key And pair.Value == myPair.Value Then
         'Do stuff
    End If
Next

I am not sure whether you need to write a better equality check

Raynos
This isn't very efficient. If you already know the key, all you need to do is look up the value for it, if any, and see if it matches the value you already heave.
Steven Sudit
True, for some reason I treated as a list of keyvaluepairs instead of a dictionary, just get the value for particular key and check againts your own value.
Raynos
Thanks , I added more to the question because I need to delete a datarow but I also need to search it multiple times .?
Adonis L
I havent done enough VB to get my head around it I'm afraid. I answered it in C# by accident and translated that. someone else can probably give you a more ooncrete solution
Raynos
thanks for your help
Adonis L
A: 

I was able to resolve it by checking with

 If Not args.Contains(args2) Then
                        datarow.Delete()


      ds.AcceptChanges()
Adonis L