且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将此代码从C#转换为VB.NET

更新时间:2022-10-16 12:07:29

您可以转换 csharp-to-vb / [ ^ ]


您无需进行手动转换。您可以在线进行自动翻译(翻译,而不是转换),为了获得全面性和***质量,您可以使用开源ILSpy离线转换整个程序集。请参阅我的过去的答案以获得进一步的指示:



代码解释,C#到VB.NET [ ^ ]。



-SA

We are coding on a game with Unity3D and using NOQSL via GameSparks Backend.

I also want to use GameSparks via Visual Studio.
Now I stumble across Delegate & lambda functions. I sit for two days and can not do to convert it.

We have to call method sendAsync(). The method calls asynchrone build(). The response of build() should be send to callback().


What I have so far:

C#

public void sendAsync(Action<IDictionary<string, object>> callback)
{
    build().Send((response) => { callback(response.JSONData); });
}
private GameSparks.Api.Requests.CustomRequest build()
{
    CustomRequest r = new CustomRequest(data);
    //add scriptdata to request when not null
    if (scriptData != null)
    {
        r.SetScriptData(new GameSparks.Core.GSRequestData(scriptData));
    }
    return r;
}



VB.NET

Public Sub sendAsync(callback As Action(Of IDictionary(Of String, Object)))
    build().Send((response) = Function()
                                  callback(response.JSONData)
                              End Function)
End Sub
'
Private Function build() As CustomRequest
    Dim r As CustomRequest = New CustomRequest(data)

    'add scriptdata to request when not null
    If Not IsNothing(scriptData) Then
        r.SetScriptData(New GSRequestData(scriptData))
    End If
    Return r
End Function



The problem is that VB doesn't know 'response' (parameter for callback).
I would be very happy if someone shows me the right way.

You can convert code in csharp-to-vb/[^]


You don't need to do manual "conversions". You can do automatic translation (translation, not "conversion") online, and for comprehensiveness and best quality, you can convert a whole assembly off-line, using open-source ILSpy. Please see my past answer for further instructions:

Code Interpretation, C# to VB.NET[^].

—SA