vb.net 是否有与下划线( _ )行续行相反的内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34950274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there an opposite of the underscore( _ ) line continuation?
提问by user81993
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
回答by Han
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.
您也可以尝试使用动作委托。但是如果你想把它们放在 1 行中,它只能有 1 个语句。
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.
如果要返回值而不是 Action 委托,请使用 Func 委托。
回答by Cody Gray
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 Inheritsin the class body. And you can't even blame it on my C++ roots, because VB was my first language.
不知何故,这对我来说似乎比将 放在Inherits课堂主体中更合乎逻辑。你甚至不能把它归咎于我的 C++ 根源,因为 VB 是我的第一语言。

