VB Array 問題

2008-01-21 9:22 am
a)write a seclaration statement(dim statement) to store the four team members'names(A,B,C,D) into an array name team(4)

b)fi we want to increase the size of the array to six(i.e team(6))after the above statement is declared,what should we do? Writedown a statement to achieve this without preserving its original contents, and also a statement that can preservethe original contents

c)wrote a seclaration statement for team() without specifying an upper bound for it

HELP ME 解答里d問題

回答 (2)

2008-01-21 12:21 pm
✔ 最佳答案

a)write a seclaration statement(dim statement) to store the four team members'names(A,B,C,D) into an array name team(4)

Dim team() As String = new String(4){"A","B","C","D"}
alternatively, if you want to split into more lines, you can write: Dim team(4) As Sring
'declaring an array
sport(0) = "A"
sport(1) = "B"
sport(2) = "C"
sport(3) = "D" Since array indices start at 0, the maximum index is one lower than the size of the array

b)fi we want to increase the size of the array to six(i.e team(6))after the above statement is declared,what should we do?
Writedown a statement to achieve this without preserving its original contents, and also a statement that can preservethe original contents

The Redim command increases the size of the existing array. All existing elements are lost. ReDim team(6) as String The old array team(4) is no longer referenced, and is put on the list for garbage collection.
To preserve the existing values, we need the keyword Preserve" ReDim Preserve team(25) as String
c)write a declaration statement for team() without specifying an upper bound for it
Dim team() as String will declare the variable team as an array without specifying an upper bound. This allows the specification of an upper bound during execution depending on the problem requirements, such as: team()=new String(20)
2008-01-21 12:08 pm
a:佢要你用team(4)去儲存4個team既稱
b:佢要你將4個team加至6個並寫出不保留原有資料同保留原有資料既方法
c:我諗佢要你用番team就可以,唔需要轉為Team/TEAM


收錄日期: 2021-04-13 14:59:48
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080121000051KK00310

檢視 Wayback Machine 備份