深入了解VB.NET對(duì)象列表
#T#VB.NET有很多值得學(xué)習(xí)的地方,這里我們主要介紹VB.NET對(duì)象列表。***步是要?jiǎng)?chuàng)建一個(gè)同用列表,你可以從多種途徑獲取數(shù)據(jù),但是最簡(jiǎn)單的方法是添加。文本中,我們會(huì)編寫(xiě)代碼以便為舉例中的集來(lái)分類。因此,下面我們就來(lái)講講創(chuàng)建集的代碼。首先,我需要一個(gè)能代表集中的bottle的對(duì)象。為此而編寫(xiě)的代碼是完全符合標(biāo)準(zhǔn)的,而且事實(shí)上,vb.net 2008 express intellisense會(huì)為你寫(xiě)好大部分的代碼。以下是我的VB.NET對(duì)象列表:
- public class bottle "internalproperties"public property brand() as string
- public property name() as string
- public property category() as string
- public property size() as decimal
- public sub new( _
- end sub
- end class
- 為了創(chuàng)建集,我需要添加項(xiàng)目:
- dim cabinet as list(of bottle) = _ "new list(of bottle)cabinet.add(new bottle( _
- "castle creek", _
- "uintah blanc", _
- "wine", 750))
- cabinet.add(new bottle( _
- "zion canyon brewing company", _
- "springdale amber ale", _
- "beer", 355))
- cabinet.add(new bottle( _
- "spanish valley vineyards", _
- "syrah", _
- "wine", 750))
- cabinet.add(new bottle( _
- "wasatch beers", _
- "polygamy porter", _
- "beer", 355))cabinet.add(new bottle( _
- "squatters beer", _
- "provo girl pilsner", _
- "beer", 355))
所有的這些都是vb.net1.0中的標(biāo)準(zhǔn)代碼。但是,要通過(guò)定義我們自己的bottle對(duì)象來(lái)注明。我們會(huì)在相同集中的多類型中獲益,大家把VB.NET對(duì)象列表的例子記下來(lái)吧。