Can anyone explain why the following occurs:
String.Format(null, "foo") // Returns foo
String.Format((string)null, "foo") // Throws ArgumentNullException:
// Value cannot be null.
// Parameter name: format
Thanks.
Its calling a different overload.
string.Format(null, "");
//calls
public static string Format(IFormatProvider provider, string format, params object[] args);
MSDN Method Link describing above.
string.Format((string)null, "");
//Calls (and this one throws ArgumentException)
public static string Format(string format, object arg0);
MSDN Method Link describing above.
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