VB.NET共享成員變量創(chuàng)建技巧解析
作者:佚名
VB.NET共享成員變量的創(chuàng)建,只需要在變量名前面加上一個shared關(guān)鍵字就可以完成。具體的操作方法會在文中給出,希望能給大家?guī)硇椭?/div>
VB.NET的推出,極大的吸引了編程人員的眼球。因為其特有的一些性質(zhì)特點可以大大提高編程人員編程效率。我們應(yīng)當在實踐中積累經(jīng)驗加深對此的印象。在這里就先為大家介紹一下有關(guān)VB.NET共享成員變量的相關(guān)創(chuàng)建方法,方便大家理解。
在某些時候,可能需要在各個對象之間共享某個成員變量(當一個對象向變量賦值時,每個對象都可以看到相同的值),要創(chuàng)建VB.NET共享成員變量,只要在變量名前加shared關(guān)鍵字,例如
- module module1
- class student
- public name as string
- public shared
studentcount=0- public sub new(byval
name as string)- me.name=name
- studentcountstudentcount
=studentcount+1- end sub
- protected overrides
sub finalize()- studentcountstudentcount
=studentcount-1- end sub
- end class
- sub main()
- dim a = new student("hans")
- console.writeline
("student count{0}",
a.studentcount)- end sub
- end module
VB.NET共享成員變量的具體創(chuàng)建方法就為大家介紹到這里。
【編輯推薦】
責任編輯:曹凱
來源:
CSDN


相關(guān)推薦




