VB.Net List.Find. Pass values to predicate

Posted by Beta033 on Stack Overflow See other posts from Stack Overflow or by Beta033
Published on 2010-04-16T20:04:25Z Indexed on 2010/04/16 20:33 UTC
Read the original article Hit count: 267

Filed under:

Having a bit of trouble using the List.Find with a custom predicate

i have a function that does this

private function test ()
    Dim test As Integer = keys.Find(AddressOf FindByOldKeyAndName).NewKey

here's the function for the predicate

Private Shared Function FindByOldKeyAndName(ByVal k As KeyObj) As Boolean
        If k.OldKey = currentKey.OldKey And k.KeyName = currentKey.KeyName Then
            Return True
        Else
            Return False
        End If


    End Function

by doing it this way means i have to have a shared "currentKey" object in the class, and i know there has to be a way to pass in the values i'm interested in of CurrentKey (namely, keyname, and oldkey)

ideally i'd like to call it by something like keys.Find(AddressOf FindByOldKeyAndName(Name,OldVal))

however when i do this i get compiler errors.

How do i call this method and pass in the values?

© Stack Overflow or respective owner

Related posts about vb.net