Compiler discrepancy with string.Empty RRS feed

  • Question

  • Take the example of the following method:

               public void Test(string t = string.Empty)

    It fails with an error error CS1736: Default parameter value for 't' must be a compile-time constant.

    Isn't string.Empty a compile time constant?

    Monday, December 10, 2012 9:40 PM


  • No, it's a read only field, as can be seen from the documentation:

    public static readonly string Empty

    • Proposed as answer by Pieter Geerkens Monday, December 10, 2012 9:55 PM
    • Marked as answer by Bob Shen Thursday, December 20, 2012 6:32 AM
    Monday, December 10, 2012 9:50 PM