删除etudianttemp() = ... => etudianttemp = ... 中的括号,如Guffa's answer 中所述(不要忘记将他的答案标记为已接受)
我将补充一点,您应该在尝试使用 @987654325 在循环中分配值之前初始化您的 tableau 数组大小 @ 和 j。顺便说一句,如果您删除了代码中的某些行以本地化您的问题,请丢弃此答案:)。
Dim tableautemp() As String = IO.File.ReadAllLines(nomfichier)
Dim etudianttemp() As String
Dim tailleDimensionJ As Int32 = 6 ' edit accordingly.. Caution: Base 0 => 7 items
Redim tableau(tailleDimensionJ, tableautemp.length - 1) ' here !
For i As Integer = 0 To tableautemp.Length - 1
etudianttemp = tableautemp(i).Split(";"c)
For j As Integer = 0 To tailleDimensionJ ' and here !
tableau(j, i) = etudianttemp(j)
Next
Next
如果没有固定大小的 J 维度,则应在运行时通过首先解析每个 tableautemp(i) 来设置 tailleDimensionJ,只保留最大项目数。
Dim tableautemp() As String = IO.File.ReadAllLines(nomfichier)
Dim etudianttemp() As String
Dim tailleDimensionJ As Int32 = 0
For i As Integer = 0 To tableautemp.Length - 1
etudianttemp = tableautemp(i).Split(";"c)
If tailleDimensionJ < (etudianttemp.Length - 1)
tailleDimensionJ = etudianttemp.Length - 1
End If
Next
Redim tableau(tailleDimensionJ, tableautemp.length - 1)
For i As Integer = 0 To tableautemp.Length - 1
etudianttemp = tableautemp(i).Split(";"c)
For j As Integer = 0 To etudianttemp.Length - 1 ' <- change this
tableau(j, i) = etudianttemp(j)
Next
Next
[FR] Vous devriez initialiser la taille de votre variable tableau avant de lui assigner des valeurs dans la boucle for à l'aide de i et j。 Bien entendu, si vous aviez supprimé des lignes de code pour bien cibler le soucis, veuillez ignorer cette remarque :)