对于c#匿名代码块,什么是vb.net等价物?

时间:2016-09-25 15:05:39

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

此代码的VB.NET等价物是什么

void foo()
{
    ...
    { //anonymous code block starts here
         ...
    } //anonymous code block ends here
}

2 个答案:

答案 0 :(得分:1)

VB.NET中没有等效的匿名代码块。

您可以使用if true:

进行模拟
Imports System.IO

Public Class CPWBBackground
Dim _selectedScreenNo As Integer
Dim _screenWidth As Integer = 400
Dim _screenHeight As Integer = 300
Dim _CPWIni As New Dictionary(Of String, String)
Dim clArgs() As String = Environment.GetCommandLineArgs()

Protected Overloads Overrides ReadOnly Property ShowWithoutActivation() As Boolean
    Get
        Return True
    End Get
End Property

Private Sub FromActivate() Handles Me.Activated
    MsgBox("blurp")
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

    'exe [1] [2] / [3] [4]
    ' 1: ScreenNumber
    ' 2: ImgFile
    ' 3: Screen Width
    ' 4: Screen Height
    '  Me.Opacity = 0

    'TestFileExists
    If Not File.Exists(clArgs(2)) Then
        Debug.WriteLine("File doesn't exist. Closing..")
        Application.Exit()
    End If

    _selectedScreenNo = clArgs(1)

    'Set vars
    Try
        _screenWidth = Screen.AllScreens(_selectedScreenNo).Bounds.Width
        _screenHeight = Screen.AllScreens(_selectedScreenNo).Bounds.Height
        'Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Me.Location = New Point(0, 0)
        If clArgs.Count > 3 Then
            If clArgs.Count < 5 Then
                'MsgBox("There should be either 2 or 4 arguments - only 3 - please check your command line.")
                Debug.WriteLine("Not enough args. Closing.")
                Application.Exit()
            Else
                _screenWidth = clArgs(3)
                _screenHeight = clArgs(4)
            End If
        End If
        Me.Size = New Size(_screenWidth, _screenHeight)
        Me.ShowInTaskbar = False

        PictureBox1.Size = New Size(_screenWidth, _screenHeight)
        Me.Location = Screen.AllScreens(_selectedScreenNo).Bounds.Location + New Point(0, 0)
        Dim fs As FileStream
        Dim FreedImage As Image
        fs = New FileStream(clArgs(2), FileMode.Open)
        FreedImage = Image.FromStream(fs)
        fs.Close()
        PictureBox1.BackgroundImage = FreedImage
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
    Catch ex As Exception
        Application.Exit()
    End Try

End Sub

Private Sub CPWBBackground_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    NotifyIcon1.Dispose()
End Sub

Private Sub CloseToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CloseToolStripMenuItem.Click
    Me.Close()
End Sub

End Class

或者,如果您不需要块范围,则可以使用以下区域:

If True Then
End If

答案 1 :(得分:0)

最接近的是:

If True Then ' anonymous code block starts here
    ' ...
End If ' anonymous code block ends here