Home > Net >  C# to VB.net delegate conversiom
C# to VB.net delegate conversiom

Time:12-20

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

CodePudding user response:

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
  • Related