c# - StringBuilder AppendFormat IEnumarble -
i have string builder , list of object ,
int[] values = new int[] {1,2}; stringbuilder builder = new stringbuilder(); builder.appendformat("{0}, {1}", values );
i see intellisense error
none existing arguments in format string
why seeing error ,and how should use list parameters inside appendformat
the overload of appendformat
using (or compiler decided use) has following signature:
public stringbuilder appendformat(string format, object arg0)
it expecting single argument , therefore format
contains 2 arguments ("{0}, {1}"
) invalid.
your intention pass array multiple arguments, overload need use following:
public stringbuilder appendformat(string format, params object[] args)
note second argument object[]
, not int[]
. make code use overload, need convert int
array object
array this:
builder.appendformat("{0}, {1}", values.cast<object>().toarray());
Comments
Post a Comment