深入了解VB.NET對象列表
#T#VB.NET有很多值得學習的地方,這里我們主要介紹VB.NET對象列表。***步是要創(chuàng)建一個同用列表,你可以從多種途徑獲取數(shù)據(jù),但是最簡單的方法是添加。文本中,我們會編寫代碼以便為舉例中的集來分類。因此,下面我們就來講講創(chuàng)建集的代碼。首先,我需要一個能代表集中的bottle的對象。為此而編寫的代碼是完全符合標準的,而且事實上,vb.net 2008 express intellisense會為你寫好大部分的代碼。以下是我的VB.NET對象列表:
- 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)建集,我需要添加項目:
- 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中的標準代碼。但是,要通過定義我們自己的bottle對象來注明。我們會在相同集中的多類型中獲益,大家把VB.NET對象列表的例子記下來吧。