Vb.NET String.Format con ArrayList
-
22-10-2019 - |
Domanda
Sto cercando di utilizzare un ArrayList come parametro per String.Format.
msg = msg & String.Format("<td>{0}</td>" & _
"<td>{1}</td>" & _
"<td>{2}</td>" & _
"<td>{3}</td>" & _
"<td>{4}</td>" & _
"<td>{5}</td>" & _
"<td>{6}</td>" & _
"<td>{7}</td>" & _
"<td>{8}</td>", param)
dove param è un ArrayList e il contenuto sono quindi (copiato da lista di controllo):
+ (0) 9 {Integer} Object
+ (1) 3 {Integer} Object
+ (2) 5 {Integer} Object
+ (3) "180" {String} Object
+ (4) 0D {Decimal} Object
+ (5) 6.788D {Decimal} Object
+ (6) #3/13/2009# {Date} Object
+ (7) "2004" {String} Object
+ (8) "" {String} Object
Ma questo codice genera un FormatException
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
Mi sbaglio che è possibile utilizzare un ArrayList? Se è possibile, eventuali indizi utili a capire il motivo per cui sarebbe gettando un tale errore?
Grazie
Soluzione
Ha accettare un ArrayList
?
Hai provato:
"<td>{8}</td>", param.ToArray())
Altri suggerimenti
Probabilmente necessario passare in una matrice di oggetti e non un ArrayList. Se si modifica il codice in quanto tale, si può vedere che cosa sta andando male:
msg = msg & String.Format("<td>{0}</td>", param)
Si dovrebbe stampare qualcosa come
System.ArrayList Hai provato questo?
msg = msg & String.Format("<td>{0}</td>" & _ "<td>{1}</td>" & _ "<td>{2}</td>" & _ "<td>{3}</td>" & _ "<td>{4}</td>" & _ "<td>{5}</td>" & _ "<td>{6}</td>" & _ "<td>{7}</td>" & _ "<td>{8}</td>", param.ToArray())
Autorizzato sotto: CC-BY-SA insieme a attribuzioneNon affiliato a StackOverflow