简体   繁体   中英

Convert c# code with inline delegate to vb.net

I need to convert this code to vb.net

public IDisposable WriteLock()
{
    EnterWriteLock();
    return new LockDisposer(delegate() { ExitWriteLock(); });
}

This is what I got with the online converters

Public Function WriteLock() As IDisposable
    EnterWriteLock()
    Return New LockDisposer(Sub() ExitWriteLock()) <-- Error Line
End Function

I am using .net 2.0

Public Function WriteLock() As IDisposable
     EnterWriteLock()
     Return New LockDisposer(AddressOf ExitWriteLock)
End Function

Your code is missing end sub of the delegate:

Public Function WriteLock() As IDisposable
    Return New LockDisposer(Sub()
                                ExitWriteLock()
                            End Sub) 
End Function

Live Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM