多语言展示
当前在线:1605今日阅读:27今日分享:41

vb.net数据结构——常量

vb.net中的常量
工具/原料

visual studio 2015

vb.net常量介绍
1

Public Class Form1       'File name constant    Private Const strFileName As String = 'C:\Temp\Hello.txt'定义模块级别的常量,如下图:

2

按钮1中的代码Private Sub btnOne_Click(sender As Object, e As EventArgs) Handles btnOne.Click     'Using a constant    MessageBox.Show('1: ' & strFileName, 'Constants Demo')End Sub

3

按钮2中的代码Private Sub btnOne_Click(sender As Object, e As EventArgs) Handles btnOne.Click     'Using a constant    MessageBox.Show('2: ' & strFileName, 'Constants Demo')End Sub

4

按钮3中的代码Private Sub btnOne_Click(sender As Object, e As EventArgs) Handles btnOne.Click     'Using a constant    MessageBox.Show('3: ' & strFileName, 'Constants Demo')End Sub

5

界面及执行结果,效果图如下:

常量的其他定义方法

Public Const intHoursAsleepPerDay As Integer = 8Public Const intRichardsTypicalState As DayAction = DayAction.AtWork

structure数据类型
1

Public Structure Customer     'Public members    Public FirstName As String    Public LastName As String    Public Email As StringEnd Structure

2

完整代码如下:Public Structure Customer    'Public members    Public FirstName As String    Public LastName As String    Public Email As String       Public Overrides Function ToString() As String        Return Name & ' (' & Email & ')'    End FunctionEnd Structure

3

Private Sub btnListCustomer_Click(sender As Object,            e As EventArgs) Handles btnListCustomer.Click     'Create a new customer    Dim objCustomer As Customer    objCustomer.FirstName = 'Michael'    objCustomer.LastName = 'Dell'    objCustomer.Email = 'mdell@somecompany.com'     'Display the customer    DisplayCustomer(objCustomer)End Sub''===========================Public Sub DisplayCustomer(customer As Customer)    'Display the customer details on the form    txtFirstName.Text = customer.FirstName    txtLastName.Text = customer.LastName    txtEmail.Text = customer.EmailEnd Sub

4

'Name property  Public ReadOnly Property Name() As String     Get         Return FirstName & ' ' & LastName     End Get End Property

推荐信息