[VB.NET Tips]程序的启动和终止

当执行一个VB.NET应用程序时,CLR会把IL翻译成x86指令,并且寻找一个名为Main的方法。
并从该方法开始执行程序。Main方法也称为程序的"入口"(entry point)。

入口方法可以采用不同的形式:

1. 不带参数的Main方法

    Module Module1

        Sub Main()

            Console.WriteLine("Hello World!")

            Console.Read()

        End Sub

    End Module

2.带参数的Main方法

    Module Module1

        Sub Main(ByVal Args() As String)

            Console.WriteLine("Hello VB.NET!")

            For Each arg As String In Args

                Console.WriteLine(arg)

            Next

            Console.Read()

        End Sub

    End Module

还可以使用另外一种写法

    Module Module1

        Sub Main()

            Console.WriteLine("Hello VB.NET!")

            '获得的参数第一个为程序的完整的路径名称
            For Each arg As String In Environment.GetCommandLineArgs()

                Console.WriteLine(arg)

            Next

            Console.Read()

        End Sub

    End Module

猜你喜欢

转载自www.cnblogs.com/tengwei6328/p/11257157.html