VB.Net - 程序结构

在我们学习VB.Net编程语言的基本构建块之前,让我们看看一个最小的VB.Net程序结构,以便我们可以将它作为未来的章节的参考。


VB.Net Hello World示例

一个VB.Net程序主要由以下几部分组成:


让我们看一个简单的代码,打印单词“Hello World”:

Imports System
Module Module1
   'This program will display Hello World 
   Sub Main()
      Console.WriteLine("Hello World")
      Console.ReadKey()
   End Sub
End Module


当上述代码被编译和执行时,它产生了以下结果:

Hello, World!

让我们来看看上面的程序中的各个部分:

编译和执行VB.Net程序:

如果您使用Visual Studio.Net IDE,请执行以下步骤:


您可以使用命令行而不是Visual Studio IDE编译VB.Net程序: