Is there the opposite of continuing the underline (_)?

Underscore allows me to do such things

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

Are there any opposite notation for this? For example, if it were, then I could do

 Public Sub derp(x as Integer) ¯ Msgbox(x) ¯ End Sub 
+5
source share
2 answers

You can try using a colon. But you cannot put the body of function / sub on 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 operator if you want to put them in 1 line.

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

If you want to have multiple lines, you write them 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 the Func delegate if you want to return a value instead of the Action delegate.

+1
source

Of course, the colon:

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

But do not abuse it. The compiler does not charge per line.

The only time I use is when I establish an inheritance relationship:

 Public Class Rectangle : Inherits Shape ... End Class 

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

0
source

Source: https://habr.com/ru/post/1241255/


All Articles