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

Categories

0 votes
781 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...