有没有办法缩短这个?

时间:2023-01-06 11:11:34

I am currently using the following code to display a dialog in WPF:

我目前正在使用以下代码在WPF中显示一个对话框:

Dim wAbout As New About
wAbout.ShowDialog()

Is there a way to shorten this to one statement only?

有没有办法将此缩短为一个陈述?

Already tried New About.ShowDialog() and (New About()).ShowDialog(), won't work.

已经尝试过New About.ShowDialog()和(New About())。ShowDialog(),无法正常工作。

I am using VBv10 if that may help.

我正在使用VBv10,如果这可能会有所帮助。

3 个解决方案

#1


3  

No, in Visual Basic declaring the variable and then running a method against it in two separate lines is the shortest way you can do that. But that's probably good because making the code one line would make it less readable.

不,在Visual Basic中声明变量然后在两个单独的行中针对它运行方法是最简单的方法。但这可能是好的,因为将代码排成一行会降低其可读性。

#2


1  

This seem to work for me:

这似乎对我有用:

Private Sub Form1_Click(sender As Object, e As System.EventArgs) Handles Me.Click
     Dim a = (New About).ShowDialog()
End Sub

#3


0  

There's the Call keyword for this purpose:

为此目的有Call关键字:

Call New About().ShowDialog()

#1


3  

No, in Visual Basic declaring the variable and then running a method against it in two separate lines is the shortest way you can do that. But that's probably good because making the code one line would make it less readable.

不,在Visual Basic中声明变量然后在两个单独的行中针对它运行方法是最简单的方法。但这可能是好的,因为将代码排成一行会降低其可读性。

#2


1  

This seem to work for me:

这似乎对我有用:

Private Sub Form1_Click(sender As Object, e As System.EventArgs) Handles Me.Click
     Dim a = (New About).ShowDialog()
End Sub

#3


0  

There's the Call keyword for this purpose:

为此目的有Call关键字:

Call New About().ShowDialog()