如何将此代码从C#转换为VB.NET [英] How do I convert this code from C# to VB.NET
问题描述
我们正在编写Unity3D游戏并通过GameSparks后端使用NOQSL。
我也想通过Visual Studio使用GameSparks。
现在我偶然发现了代表和& lambda函数。我坐了两天,不能转换它。
我们必须调用方法sendAsync()。该方法调用asynchrone build()。 build()的响应应该发送到callback()。
到目前为止我有什么:
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);
// 添加scriptdata以在非空时请求
if (scriptData!= null )
{
r.SetScriptData( new GameSparks.Core.GSRequestData(scriptData));
}
return r;
}
VB.NET
公共 Sub sendAsync(callback As Action( IDictionary( String , Object )))
build()。Send((response)= Function ()
callback( response.JSONData)
结束 功能)
结束 Sub
'
私有 功能 build()作为 CustomRequest
Dim r As CustomRequest = 新 CustomRequest(数据)
' 添加scriptdata以在非空时请求
如果 不 IsNothing(scriptData)然后
r.SetScriptData(新 GSRequestData(scriptData))
结束 如果
返回 r
结束 功能
问题是VB不知道'响应'(回调参数)。
I如果有人以正确的方式向我显示,那将非常高兴。
您可以转换 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
这篇关于如何将此代码从C#转换为VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!