是否与下划线(_)线的延续相反?

时间:2021-03-16 22:30:46

The underscore allows me to do things like this

下划线允许我这样做

    Public Sub derp _
        (x As Integer)
        MsgBox(x)
    End Sub

Is there any opposite notation for this? For example, if it was ¯ then I could do

有什么相反的符号吗?例如,如果它是¯然后我可以做

Public Sub derp(x as Integer) ¯ Msgbox(x) ¯ End Sub

2 个解决方案

#1


1  

You can try using a colon. But you can't put the function/sub body in the same line as the declaration of the function/sub.

你可以试试用冒号。但是你不能把函数/子主体和函数/子的声明放在同一条线上。

Public Sub derp(x As Integer)
    MsgBox(x) : MsgBox("Hello, world") : End Sub

You can also try using an action delegate. But it can only have 1 statement if you want to put them in 1 line.

您还可以尝试使用action委托。但是如果你想把它们放到一行里,它只能有一个表述。

Public herp As Action(Of Integer) = Sub(x) MsgBox(x)

If you want to have multiple line, you write it like this (you can use colons, if you want):

如果你想要多行,你可以这样写(你可以用冒号,如果你想):

Public herp As Action(Of Integer) = Sub(x)
                                        MsgBox(x)
                                        MsgBox("Hello, world")
                                    End Sub

Use Func delegate if you want to return a value instead of Action delegate.

如果您想返回值而不是动作委托,请使用Func委托。

#2


0  

Sure—the colon:

确保冒号:

Public Sub derp(x as Integer) : MsgBox(x) : End Sub

But don't abuse this. The compiler doesn't charge by the line.

但是不要滥用。编译器不按行收费。

About the only time I use it is when I'm establishing an inheritance relationship:

我唯一使用它的时候是当我建立一个继承关系时:

Public Class Rectangle : Inherits Shape
   ...
End Class

Somehow, that just seems more logical to me than putting the Inherits in the class body. And you can't even blame it on my C++ roots, because VB was my first language.

不知何故,在我看来,这比将继承放到类体中更符合逻辑。你甚至不能责怪我的c++根,因为VB是我的第一语言。

#1


1  

You can try using a colon. But you can't put the function/sub body in the same line as the declaration of the function/sub.

你可以试试用冒号。但是你不能把函数/子主体和函数/子的声明放在同一条线上。

Public Sub derp(x As Integer)
    MsgBox(x) : MsgBox("Hello, world") : End Sub

You can also try using an action delegate. But it can only have 1 statement if you want to put them in 1 line.

您还可以尝试使用action委托。但是如果你想把它们放到一行里,它只能有一个表述。

Public herp As Action(Of Integer) = Sub(x) MsgBox(x)

If you want to have multiple line, you write it like this (you can use colons, if you want):

如果你想要多行,你可以这样写(你可以用冒号,如果你想):

Public herp As Action(Of Integer) = Sub(x)
                                        MsgBox(x)
                                        MsgBox("Hello, world")
                                    End Sub

Use Func delegate if you want to return a value instead of Action delegate.

如果您想返回值而不是动作委托,请使用Func委托。

#2


0  

Sure—the colon:

确保冒号:

Public Sub derp(x as Integer) : MsgBox(x) : End Sub

But don't abuse this. The compiler doesn't charge by the line.

但是不要滥用。编译器不按行收费。

About the only time I use it is when I'm establishing an inheritance relationship:

我唯一使用它的时候是当我建立一个继承关系时:

Public Class Rectangle : Inherits Shape
   ...
End Class

Somehow, that just seems more logical to me than putting the Inherits in the class body. And you can't even blame it on my C++ roots, because VB was my first language.

不知何故,在我看来,这比将继承放到类体中更符合逻辑。你甚至不能责怪我的c++根,因为VB是我的第一语言。