加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

需要帮助将C#转换为VB

发布时间:2020-12-15 08:41:54 所属栏目:百科 来源:网络整理
导读:我用一个工具将C#转换为VB.当我在VB中运行程序时,我收到以下错误: Events cannot be declared with a delegate type that has a return type. 我该如何更正此代码? C#: using System;[assembly: CLSCompliant(true)]namespace Link.API{ public delegate
我用一个工具将C#转换为VB.当我在VB中运行程序时,我收到以下错误:

Events cannot be declared with a delegate type that has a return type.

我该如何更正此代码?

C#:

using System;
[assembly: CLSCompliant(true)]

namespace Link.API
{
  public delegate decimal DecimalStringDelegate(string s);
  public delegate long OrderDelegateStatus(Order o);
  public delegate void LongDelegate(long val);
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Link.API
{
  public interface TLServer
  {
    event LongDelegate newOrderCancelRequest;
    event OrderDelegateStatus newSendOrderRequest;
    string ClientName(int clientnum);
    bool SymbolSubscribed(string sym);

    Basket AllClientBasket { get; }
  }
}

VB.NET:

Imports System.Text
Imports System.Collections.Generic
Imports System
<Assembly: CLSCompliant(True)>

Namespace Link.API
  Public Delegate Function DecimalStringDelegate(ByVal s As String) As Decimal
  Public Delegate Function OrderDelegateStatus(ByVal o As Order) As Long
  Public Delegate Sub LongDelegate(ByVal val As Long)
End Namespace

Namespace Link.API
  Public Interface Server
    Event newOrderCancelRequest As LongDelegate
    Event newSendOrderRequest As OrderDelegateStatus
    Function ClientName(ByVal clientnum As Integer) As String
    Function SymbolSubscribed(ByVal sym As String) As Boolean
    ReadOnly Property AllClientBasket() As Basket
  End Interface
End Namespace

解决方法

正如错误所暗示的那样,VB不支持使用具有返回类型的委托的事件.所以你不能直接转换代码.一种解决方法是将委托更改为使用ByRef参数:
Public Delegate Sub DecimalStringDelegate(ByVal s As String,ByRef retVal as Decimal)
Public Delegate Sub OrderDelegateStatus(ByVal o As Order,ByRef retVal As Long)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读