2011年10月31日 星期一

宣告 class 為陣列使用 (json 運用)

參考來源

' Create an array of creature classes
Dim creatureArray(10) As creatures

Dim i As Integer = 0

' Load up the array with 10 creatures named MonsterMan0 - MonsterMan9
For i = 0 To 9
   Dim mycreature As creatures = New creatures()
   ' Set his name and his age (all our monsters are clones, so they have the same age! (you could assign whatever data you wanted)
   mycreature.name = "MonsterMan" & i.ToString
   mycreature.age = 100

   ' Store our copy of the creature into the array of creatures
   creatureArray(i) = mycreature
Next

' Show the name of the 5th monster who is in slot 4 because the array starts at 0, so his name is MonsterMan4 
MessageBox.Show("The 5th monster is named: " & creatureArray(4).name)

沒有留言:

張貼留言