I'm trying to use string builder and append format to build some html. How can I use the verbatim string literal and append format without getting the following error: "Index (zero based) must be greater than or equal to zero and less than the size of the argument list."
See this example:
StringBuilder sb = new StringBuilder(5469);<br />
sb.AppendFormat(@"<td width=""155"">{0}</td>", localVariable); // zero index error here <br />
return sb;
Is the type of localVariable an array? If so the array is being interpreted as a params array instead of the first argument to a params array. To fix this you need to explicitly cast it to object when calling AppendFormat
sb.AppendFormat(@"{0}", (object)localVariable);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With