How to set optional parameter without compile-time constant
问题 Is there a way to write the C# method below: public string Download(Encoding contentEncoding = null) { defaultEncoding = contentEncoding ?? Encoding.UTF8; // codes... } with a default parameter added so it looks like this: public string Download(Encoding contentEncoding = Encoding.UTF8) { // codes... } without using a compile-time constant? 回答1: In short. No. Optional parameters are required to be compile time constants or value types. From Named and Optional Arguments (C# Programming Guide)