【问题标题】:Can anyone convert this vb.net code to C#?任何人都可以将此 vb.net 代码转换为 C# 吗?
【发布时间】:2013-03-10 20:41:24
【问题描述】:

我在将此代码(使用此FFmpeg Wrapper)转换为 C# 时遇到了麻烦,因为它是我项目的主要语言。

我试过http://www.developerfusion.com/tools/convert/vb-to-csharp/ 但结果代码对我不起作用:(

我知道这是新手请求,对不起;

代码:

    Public WithEvents MediaConverter As New FFLib.Encoder

    Private Sub ConOut(ByVal prog As String, ByVal tl As String) Handles MediaConverter.Progress
        OperationPrgrss.Value = prog
        Application.DoEvents()
    End Sub

    Private Sub stat(ByVal status) Handles MediaConverter.Status
        StatusLbl.Text = status
        Application.DoEvents()
    End Sub

【问题讨论】:

  • 您需要使用+=手动添加事件处理程序。

标签: vb.net-to-c# sharpffmpeg


【解决方案1】:

C# 没有 Handles 关键字的严格等效项;您需要做的是在构造函数中自己添加事件处理程序。

public Form1() {
    ...

    // wire up events
    MediaConverter.Progress += ConOut;
    MediaConverter.Status += stat;
}

您不需要 WithEvents 的等价物,因为它只是告诉 VB 有需要连接的事件,而在 C# 中您可以自己完成。

剩下的就是一个非常直接的翻译。 Sub 基本上是一个返回类型为void 的函数,ByValHandles 子句可以去掉,关键字是小写,其余的只是分号和大括号。

例如,

private void ConOut(String prog, String tl) {
    OperationPrgrss.Value = prog;
    Application.DoEvents();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-19
    • 1970-01-01
    • 2018-04-29
    • 1970-01-01
    • 2011-05-31
    • 1970-01-01
    相关资源
    最近更新 更多