Why do optional parameters in C# 4.0 require compile-time constants?

前端 未结 3 1573
野性不改
野性不改 2021-02-08 04:34

Also is there a way to use run-time values for optional method parameters?

3条回答
  •  旧巷少年郎
    2021-02-08 04:59

    Optional parameters are compiled into the assembly and as such (just like anything that is designated as const) they must be a compile-time constant.

    And no, you cannot use execution-time values as optional parameters.

提交回复
热议问题