Unexpected behavior from String.Format()

c#, string

Solution

It's working because it's choosing this overload:

public static String Format( IFormatProvider provider, String format, params Object[] args) { ... }

A `null` provider 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:

public static String Format(String format, Object arg0) { ... }

And of course, if it did choose that, we would have gotten an `ArgumentNullException`.

Problem

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?

Original source