在VB.NET中编写c#代码

本文关键字:代码 VB NET | 更新日期: 2023-09-27 18:07:58

我想在VB中编写此代码。净:

ModernIpg.PaymentWebServiceService ModernService = new ModernIpg.PaymentWebServiceService();
ModernService.AllowAutoRedirect = true;
ModernIpg.loginRequest req = new ModernIpg.loginRequest();
req.username = username;
req.password = password;
string Session_ID = ModernService.login(req);
ModernIpg.wsContext context = new ModernIpg.wsContext() { data = new ModernIpg.wsContextEntry[1] };
context.data[0] = new ModernIpg.wsContextEntry();
context.data[0].key = "SESSION_ID";
context.data[0].value = Session_ID;

我怎么能做到呢?

在VB.NET中编写c#代码

我找到了:

Dim ModernService As ModernIpg.PaymentWebServiceService = New ModernIpg.PaymentWebServiceService()
        ModernService.AllowAutoRedirect = True
        Dim req As ModernIpg.loginRequest = New ModernIpg.loginRequest()
        req.username = Username
        req.password = Password
        Dim Session_ID As String = ModernService.login(req)
        Dim oWscontext As ModernIpg.wsContext = New ModernIpg.wsContext() With {.data = New ModernIpg.wsContextEntry(0) {}}

        oWscontext.data(0) = New ModernIpg.wsContextEntry()
        oWscontext.data(0).key = "Session_ID"
        oWscontext.data(0).value = Session_ID

试试这个

        Dim ModernService As New ModernIpg.PaymentWebServiceService()
        ModernService.AllowAutoRedirect = True
        Dim req As ModernIpg.loginRequest = New ModernIpg.loginRequest()
        req.username = username
        req.password = password
        Dim Session_ID As String = ModernService.login(req)
        Dim context As ModernIpg.wsContext = new ModernIpg.wsContext() { data = new ModernIpg.wsContextEntry(1) }
        context.data(0) = New ModernIpg.wsContextEntry()
        context.data(0).key = "SESSION_ID"
        context.data(0).value = Session_ID​

代码应该看起来像这样

Module Module1
    Sub Main()
        Dim context As ModernIpg.wsContext = New ModernIpg.wsContext() With {.data = New ModernIpg.wsContextEntry(1)}
    End Sub
End Module
Public Class ModernIpg
    Public Class wsContext
        Public data As wsContextEntry
    End Class
    Public Class wsContextEntry
        Sub New(x As Integer)
        End Sub
    End Class
End Class​