Given the following code, I would expect to an empty result or an exception:
String.Format(null, "Hello")
Instead, the result is the string “Hello”. Why is this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s working because it’s choosing this overload:
A
nullprovider is OK, and no arguments to the varargs is also OK, and so it just prints out the string.Intuitively, we might have expected this overload:
And of course, if it did choose that, we would have gotten an
ArgumentNullException.