Main As a Function Not a Subroutine

It is also possible to define Main() as a function returning an Integer, rather than a subroutine (which never has a return value). This approach to building a Main() method has its roots in C-based languages, where returning the value 0 typically indicates the program has terminated without error. You will seldom (if ever) need to build your Main() method in this manner; however, for the sake of completion, here is one example:

Shared Function Main(ByVal args As String()) As Integer Console.WriteLine("***** Fun with Main() *****") Dim s As String For Each s In args

Console.WriteLine("Arg: {0}", s) Next

' Return a value to the OS.

Return 0 End Function

Regardless of how you define your Main() method, the purpose remains the same: interact with the types that carry out the functionality of your application. Once the final statement within the Main() method has executed, Main() exits and your application terminates.

Was this article helpful?

0 0

Post a comment