2009-09-02 101 views
0

我想知道如何將其轉換爲VB.NET。將這些行從C#轉換爲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 
+0

你試過使用反射器嗎? – David 2009-09-02 16:50:09

回答

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 
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 
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 
+2

在VB.Net中使用Raise比與事件無關檢查更具慣用 – JaredPar 2009-09-02 16:55:01

0

SharpDevelop的(又名#Develop)具有優良的代碼轉換器。它可以用於轉換單個文件或整個項目。

+0

不幸的是,在這種情況下,我們的轉換器不能很好地工作 - 在C# - > VB方向上,大多數新的C#3.0構造是尚未支持。 – Daniel 2009-09-23 22:04:51