将这些行从C#转换为VB.Net?

时间:2009-09-02 16:48:05

标签: c# vb.net

我想知道如何将其转换为VB.NET。

private void RaiseStreamVolumeNotification()
    {
        if (StreamVolume != null)
        {
            StreamVolume(this, new StreamVolumeEventArgs() { MaxSampleValues = (float[])maxSamples.Clone() });
        }

    }

public class StreamVolumeEventArgs : EventArgs
{
    public float[] MaxSampleValues { get; set; }
}

我正在尝试使用在线转换器转换它,但要么失败,要么它转换不正确。我认为最好的一个转换器将其转换为:

Public Class StreamVolumeEventArgs
    Inherits EventArgs
Private _MaxSampleValues As Single()
    Public Property MaxSampleValues() As Single()
        Get
            Return _MaxSampleValues
        End Get
        Set(ByVal value As Single())
            _MaxSampleValues = value
        End Set
    End Property
End Class

4 个答案:

答案 0 :(得分:1)

可能会有一些小问题。

Private Sub RaiseStreamVolumeNotification()
        Dim SVEA As New StreamVolumeEventArgs()
        SVEA.MaxSampleValues = CType(maxSamples.Clone(), Single())
        If Not StreamVolume Is Nothing Then
            StreamVolume(this, SVEA)
        End If
End Sub

Public Class StreamVolumeEventArgs Inheirits EventArgs
    Private _MaxSampleValues As Single()
    Public Property MaxSampleValues As Single()
        Get
            Return _MaxSampleValues
        End Get
        Set(value as Single())
            _MaxSampleValues = value
        End Set
    End Property
End Class

答案 1 :(得分:0)

您是否尝试过单独转换它们?你有一个看似在任何类之外的函数,后跟一个类,都在同一个代码空间中。

您的功能应转换为

Private Sub RaiseStreamVolumeNotification()

    RaiseEvent StreamVolume(Me, New StreamVolumeEventArgs(){ .MaxSampleValues = maxSamples.Clone() })
End Sub

你的班级应转换为

Public Class StreamVolumeEventArgs
    Inherits EventArgs
Private _MaxSampleValues As Single()
    Public Property MaxSampleValues() As Single()
        Get
            Return _MaxSampleValues
        End Get
        Set(ByVal value As Single())
            _MaxSampleValues = value
        End Set
    End Property
End Class

答案 2 :(得分:0)

试试这个(假设VS2008 / VB9)

Public Sub RaiseStreamVolumeNotification() 
  Raise StreamVolume(Me, New StreamVolume() { .MaxSampleValues = maxSamples.Clone() })
End Sub

Public Class StreamVolumeEventArgs
  Inherits EventArgs

  Private _maxSampleValues As Float()
  Public Property MaxSampleValues As Float()
    Get
      Return _maxSampleValues
    End Get
    Set (value As Float())
      _maxSampleValues = value
    End Set
  End Property

End Class

答案 3 :(得分:0)

SharpDevelop(又名#Develop)拥有出色的代码转换器。它可用于转换单个文件或整个项目。