Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# to VB.net delegate conversiom

I’m trying convert C# code to VB.net and delegate stopped me.

origial code is:

using (var source = new ETWTraceEventSource(sessionName, TraceEventSourceType.Session))
        {
            Action<TraceEvent> action = delegate (TraceEvent data)
            {
                var taskName = data.TaskName;
                var EventName = data.EventName;

Row Action<>… is problem for me.
Some example will be appreciated.
Thanks, Jerry

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Using the ‘delegate’ keyword in this way is outdated legacy C# (pre-lambda operator). The modern C# way is to use the lambda operator:

Action<TraceEvent> action = (TraceEvent data) =>

The VB equivalent for both is:

Option Infer On

Using source = New ETWTraceEventSource(sessionName, TraceEventSourceType.Session)
    Dim action As Action(Of TraceEvent) = Sub(data As TraceEvent)
        Dim taskName = data.TaskName
        Dim EventName = data.EventName
    End Sub
End Using
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading