VB.Net - 声明

VB.Net - 声明

1

Dim StatementDim语句Declares and allocates storage space for one or more variables.声明和分配一个或多个变量的存储空间。

Dim number As Integer

Dim quantity As Integer = 100

Dim message As String = "Hello!"

2

Const Statement Const语句Declares and defines one or more constants.声明和定义一个或多个常量。

Const maximum As Long = 1000

Const naturalLogBase As Object

= CDec(2.7182818284)

3

Enum Statement 枚举语句Declares an enumeration and defines the values of its members.声明一个枚举并定义其成员的值。

Enum CoffeeMugSize

Jumbo

ExtraLarge

Large

Medium

Small

End Enum

4

Class Statement类语句Declares the name of a class and introduces the definition of the variables, properties, events, and procedures that the class comprises.声明类的名称,并引入该类包含的变量,属性,事件和过程的定义。

Class Box

Public length As Double

Public breadth As Double

Public height As Double

End Class

5

Structure Statement结构声明Declares the name of a structure and introduces the definition of the variables, properties, events, and procedures that the structure comprises.声明结构的名称,并引入结构所包含的变量,属性,事件和过程的定义。

Structure Box

Public length As Double

Public breadth As Double

Public height As Double

End Structure

6

Module Statement模块语句Declares the name of a module and introduces the definition of the variables, properties, events, and procedures that the module comprises.声明模块的名称,并介绍模块包含的变量,属性,事件和过程的定义。

Public Module myModule

Sub Main()

Dim user As String =

InputBox("What is your name?")

MsgBox("User name is" & user)

End Sub

End Module

7

Interface Statement接口语句Declares the name of an interface and introduces the definitions of the members that the interface comprises.声明接口的名称,并介绍接口包含的成员的定义。

Public Interface MyInterface

Sub doSomething()

End Interface

8

Function Statement函数语句Declares the name, parameters, and code that define a Function procedure.声明定义函数过程的名称,参数和代码。

Function myFunction

(ByVal n As Integer) As Double

Return 5.87 * n

End Function

9

Sub Statement子语句Declares the name, parameters, and code that define a Sub procedure.声明定义Sub过程的名称,参数和代码。

Sub mySub(ByVal s As String)

Return

End Sub

10

Declare Statement声明语句Declares a reference to a procedure implemented in an external file.声明对在外部文件中实现的过程的引用。

Declare Function getUserName

Lib "advapi32.dll"

Alias "GetUserNameA"

(

ByVal lpBuffer As String,

ByRef nSize As Integer) As Integer

11

Operator Statement运算符声明Declares the operator symbol, operands, and code that define an operator procedure on a class or structure.声明的运算符符号、 操作数和在类或结构定义一个运算符过程的代码。

Public Shared Operator +

(ByVal x As obj, ByVal y As obj) As obj

Dim r As New obj

' implemention code for r = x + y

Return r

End Operator

12

Property Statement属性声明Declares the name of a property, and the property procedures used to store and retrieve the value of the property.声明属性的名称,以及用于存储和检索属性值的属性过程。

ReadOnly Property quote() As String

Get

Return quoteString

End Get

End Property

13

Event Statement事件声明Declares a user-defined event.声明用户定义的事件。

Public Event Finished()

14

Delegate Statement委托声明Used to declare a delegate.用于声明一个委托。

Delegate Function MathOperator(

ByVal x As Double,

ByVal y As Double

) As Double

相关推荐