2011年10月31日 星期一

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

參考來源

  1. ' Create an array of creature classes
  2. Dim creatureArray(10) As creatures
  3.  
  4. Dim i As Integer = 0
  5.  
  6. ' Load up the array with 10 creatures named MonsterMan0 - MonsterMan9
  7. For i = 0 To 9
  8. Dim mycreature As creatures = New creatures()
  9. ' Set his name and his age (all our monsters are clones, so they have the same age! (you could assign whatever data you wanted)
  10. mycreature.name = "MonsterMan" & i.ToString
  11. mycreature.age = 100
  12.  
  13. ' Store our copy of the creature into the array of creatures
  14. creatureArray(i) = mycreature
  15. Next
  16.  
  17. ' 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)

沒有留言:

張貼留言