【问题标题】:Translate code from c# in vb (complex raise event)在 vb 中翻译 c# 中的代码(复杂的引发事件)
【发布时间】:2015-06-29 02:28:37
【问题描述】:

我有这段无法从 c# 翻译成 vb 的代码:

  // subscribe for errors that occur when applying changes to the client
((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);

一定是这样的:

DirectCast(syncOrchestrator.LocalProvider, SqlSyncProvider).ApplyChangeFailed += New EventHandler(Of DbApplyChangeFailedEventArgs)(AddressOf Program_ApplyChangeFailed)

我收到一条错误消息:

'Public Event ApplyChangeFailed(sender As Object, e As Microsoft.Synchronization.Data.DbApplyChangeFailedEventArgs)'是一个事件,不能直接调用。使用“RaiseEvent”语句来引发事件。

我什至不知道什么/如何提出这个问题!对我来说太复杂了:(

有人可以帮助我吗?

【问题讨论】:

  • C# 代码正在为更改失败事件添加事件处理程序。 VB 等价物是AddHandler

标签: c# vb.net


【解决方案1】:

我不知道VB如何处理事件处理程序,但从msdn文章来看:

AddHandler DirectCast(syncOrchestrator.LocalProvider, SqlSyncProvider).ApplyChangeFailed, AddressOf New EventHandler(Of DbApplyChangeFailedEventArgs)(AddressOf Program_ApplyChangeFailed)

【讨论】:

  • 使用此代码我收到以下错误:'AddressOf' 操作数必须是方法的名称(不带括号)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多