문제

I'm trying to use an arraylist as the parameter to 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)

where param is an ArrayList and the contents are thus (copied from watch list):

+       (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

But this code throws a FormatException

Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

Am I wrong that it's possible to use an arraylist? If it is possible, any clues as to why it would be throwing such an error?

Thanks

도움이 되었습니까?

해결책

Does it accept an ArrayList?

Did you try:

 "<td>{8}</td>", param.ToArray())

다른 팁

You probably need to pass in an object array and not an ArrayList. If you change the code as such you may see what is going wrong:

 msg = msg & String.Format("<td>{0}</td>", param)

It should print something like

< td>System.ArrayList< td>

Have you tried this ?

 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())
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top