VB.Net - 程序结构

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

VB.Net Hello World示例

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

  • 命名空间声明  Namespace declaration

让我们看一个简单的代码,打印单词“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!

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

  • 程序Imports System的第一行用于在程序中包括系统命名空间。The first line of the program Imports System is used to include the System namespace in the program.

- 功能 Function

- 子 Sub

- 运算符 Operator

- 获取 Get

- 组 Set

- AddHandler - RemoveHandler - 的RaiseEvent

  • 下一行('这个程序)将被编译器忽略,并且已经在程序中添加了额外的注释。

编译和执行VB.Net程序:

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

  • 启动Visual Studio。 Start Visual Studio.

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

  • 打开文本编辑器,并添加上述代码。 Open a text editor and add the above mentioned code.