Why can't I use string.Empty as an optional parameter contrary to empty quotation marks?

c#, optional-parameters

Solution

`Empty` is defined as follows:

public static readonly string Empty

It's not a constant. It's a readonly field.

Problem

I'm refining my code and noticed that at some places I had optional parameters with the default value of an empty string. I changed that to a default value from the class for empty string and guess what! Apparently there's a difference between empty quotation marks and `string.Empty`. What the duck?! (typo intended) ``` private void Khaboom(String parameter = "") { ... } private void Bazinga(String parameter = String.Empty) { ... } ``` Can someone explain to me why the duck does `Khaboom` work while `Bazinga` doesn't?! The error message whines this: Default parameter value for 'parameter' must be a compile-time constant. Well... It is!

Original source

Related problems