views:

112

answers:

3

Im not sure how to convert C# code with delegate into Visual basic code, can you help me?

List<XmlUser> matchingUsers = this.Store.Users.FindAll(delegate(XmlUser user) 
    {
        return user.Email.Equals(emailToMatch,
            StringComparison.OrdinalIgnoreCase);
    }
);
+6  A: 
Dim matchingUsers As List(Of XmlUser) = Me.Store.Users.FindAll( _
    Function(user As XmlUser) user.Email.Equals(emailToMatch, StringComparison.OrdinalIgnoreCase) _
)
Dan Tao
The trick is that this requires at least Visual Studio 2008, since the emailToMatch variable is a closure.
Joel Coehoorn
closures were available from the first time they added anonymous delegates (i.e. .NET 2.0 VS2005)
AZ
+3  A: 

Compile the code. Get .Net Reflector:

http://www.red-gate.com/products/reflector/

and Select Visual Basic for disassembling. Thats an easy way to convert between the 2 languages.

Scordo
There's a closure transformation in there. The reflected code will have significant differences from the original.
Joel Coehoorn
Yes for this code the reflected one wouldn't be that perfect, but the resulting code would work. I suggested to use reflector so he is able to solve such "conversion" problems in future without further asking.
Scordo
+1  A: 

I've used this converter with some success. I'd start there.

Also, a quick Google search should give you some good results.

Robert Greiner