Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
707 views
in Technique[技术] by (71.8m points)

vb.net - VB -Parentheses! Please explain?

Sub Main() 

    Console.WriteLine("check")   
    Console.Read()

End Sub

Why does Sub Main () need them? How do they apply to this procedure? .WriteLine("") here i am adding a value. Console.Read() is this holding the value "check" to show on console? Why why are they here. I know all you experts think this is a dumb question, however i can not wrap my head around it help! To me these are boxes that hold or pass a procedure value. Is sub main a container holding the code the uses enters? If so, why is it that when a form button is used it is full? But here a VB default unused and empty? Seems to me with no event values it should not be there....?????

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Parenthesis are required when they are required, and optional when they are optional. In the case of empty parameter/argument lists parenthesis are "just for show".

A Sub Procedure can be declared as Sub Main() or Sub Main - the parenthesis are optional when there are no parameters. Likewise, procedures/functions can be invoked without parenthesis if (and only if) no arguments are supplied.

Sub A               ' ok, no parameter list - no need for parenthesis
Sub A()             ' it's fine to use parenthesis anyway
Sub B(x as Integer) ' need parenthesis for parameter list

obj.A               ' ok, no arguments - no need for parenthesis
obj.A()             ' it's fine to use parenthesis anyway
obj.B(42)           ' need parenthesis when arguments are specified

In the above, the definitions of A and invocations of A are equivalent as the parenthesis are optional in these cases.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...