本篇文章為大家展示了VB.NET中靜態(tài)成員有什么用,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
為高安等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及高安網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、高安網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
VB.NET靜態(tài)成員
在面向?qū)ο缶幊陶Z言中,有一種被稱作靜態(tài)成員的特殊的類成員,VB.NET也有靜態(tài)成員這一概念。無需對(duì)一個(gè)對(duì)象實(shí)例化就可以使用其中的VB.NET靜態(tài)成員。例如,下面的表中,SalaryLevel類中就只包含有靜態(tài)的域:
Class SalaryLevel Public Shared Level1 As Decimal = 35000 Public Shared Level2 As Decimal = 40000 Public Shared Level3 As Decimal = 45000 Public Shared Level4 As Decimal = 50000 Public Shared Level5 As Decimal = 55000 Public Shared Level6 As Decimal = 60000 Public Shared Level7 As Decimal = 65000 Public Shared Level8 As Decimal = 70000 Public Shared Level9 As Decimal = 75000 Public Shared Level10 As Decimal = 80000 End Class
我們可以像下表中的程序所演示的那樣在程序中使用類:
Imports System Class SalaryLevel Public Shared Level1 As Decimal = 35000 Public Shared Level2 As Decimal = 40000 Public Shared Level3 As Decimal = 45000 Public Shared Level4 As Decimal = 50000 Public Shared Level5 As Decimal = 55000 Public Shared Level6 As Decimal = 60000 Public Shared Level7 As Decimal = 65000 Public Shared Level8 As Decimal = 70000 Public Shared Level9 As Decimal = 75000 Public Shared Level10 As Decimal = 80000 End Class Class Employee Dim yearlyBonus As Decimal = 4000 Public Sub PrintSalary() '使用SalaryLevel類的靜態(tài)域向Console輸出工資額 Console.Write(SalaryLevel.Level4) End Sub Public Shared Sub Main() Dim employee As Employee employee = New Employee() employee.PrintSalary() End Sub End Class
在Employee類的PrintSalary方法中,我們可以在不首先創(chuàng)建SalaryLevel類變量的情況下使用其中的靜態(tài)域Level4。不屬于VB.NET靜態(tài)成員的類成員被稱作實(shí)例成員。
上述內(nèi)容就是VB.NET中靜態(tài)成員有什么用,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。