G
Guest
I'm having trouble the string.Format() throwing exceptions and I can't figure
out what I am doing wrong.
Given the following setup code:
string[] str = { "one", "two", "three", "four" };
double[] val = { 1.0, 2.0, 3.0, 4.0 };
string fmt = "{0} {1} {2} {3}";
The following variations of string.Format() will work just fine with strings:
string s1 = String.Format(fmt, str[0], str[1], str[2], str[3]); // works
string s2 = String.Format(fmt, str); // also
works
And I can format a list of doubles like this:
string s3 = String.Format(fmt, val[0], val[1], val[2], val[3]); // works
But when I pass an array of doubles as the object[] parameter I get an
exception:
string s4 = String.Format(fmt, val); // fails
Throws exception:
"Index (zero based) must be greater than or equal to zero and less than the
size of the argument list."
Why does the array version work with strings but not doubles? Please
enlighten me? Thanks much!
Bob
out what I am doing wrong.
Given the following setup code:
string[] str = { "one", "two", "three", "four" };
double[] val = { 1.0, 2.0, 3.0, 4.0 };
string fmt = "{0} {1} {2} {3}";
The following variations of string.Format() will work just fine with strings:
string s1 = String.Format(fmt, str[0], str[1], str[2], str[3]); // works
string s2 = String.Format(fmt, str); // also
works
And I can format a list of doubles like this:
string s3 = String.Format(fmt, val[0], val[1], val[2], val[3]); // works
But when I pass an array of doubles as the object[] parameter I get an
exception:
string s4 = String.Format(fmt, val); // fails
Throws exception:
"Index (zero based) must be greater than or equal to zero and less than the
size of the argument list."
Why does the array version work with strings but not doubles? Please
enlighten me? Thanks much!
Bob