Why do I get an exception when passing “null” constant but not when passing a “null” string reference?

Just decompile the code to work out what’s going on. string.Format(“{0}”, null) calls the most specific applicable overload, which is string.Format(string, object[]). The overloads of string.Format are: Format(String, Object) Format(String, Object[]) Format(IFormatProvider, String, Object[]) Format(String, Object, Object) Format(String, Object, Object, Object) Hopefully it’s obvious why the last three options are invalid. To work out which … Read more

Why does this string extension method not throw an exception?

You are using yield return. When doing so, the compiler will rewrite your method into a function that returns a generated class that implements a state machine. Broadly speaking, it rewrites locals to fields of that class and each part of your algorithm between the yield return instructions becomes a state. You can check with … Read more