I have the code
//this runs
string[] s_items = {"0","0"};
string s_output = string.Format("{0}{1}",s_items);
//this one throws a exception
int[] i_items = {0,0};
string i_output = string.Format("{0}{1}",i_items);
why does the first one run and the second throw a exception? Why selects
int[]
the Format(String, Object)
overload
string[]
the Format(String, Object[])
overload
Some manufacturers have the 125% setting built in, which means you must set the overload protection at the motor's nameplate current. If the 125% value is not built into the relay, you must set it at the motor's nameplate current + 25%.
The overloads are determined using 125% of the FLA, 7A x 1.25 = 8.75A. The maximum allowable size for the overloads is 9.8A. The overloads can be sized at 140% of the FLA if the overloads trip at rated load or will not allow the motor to start, 7A x 1.4 = 9.8A.
A string[]
can be converted to an object[]
because they're both arrays of reference types. And all references are "equal". This is one of the nasty (array) conversions that is built into the C# language from day 1 and should not have existed but we didn't have generics and proper co/contravariance rules from day 1.
An int[]
cannot be converted to an object[]
because int
s, the things actually contained in the first array, are not references.
From the msdn documentation,
This is a problem of compiler overload resolution. Because the compiler cannot convert an array of integers to an object array, it treats the integer array as a single argument, so it calls the Format(String, Object) method.
See more here.
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