C# Dynamic Keyword — Run-time penalty?

后端 未结 6 1205
春和景丽
春和景丽 2020-12-01 14:20

Does defining an instance as dynamic in C# mean:

  1. The compiler does not perform compile-time type checking, but run-time checking takes place like it always

6条回答
  •  天命终不由人
    2020-12-01 15:13

    Well, the variable is statically typed to be of the type dynamic but beyond that the compiler doesn't do any checking as far as I know.

    Type binding is done at runtime and yes, there's a penalty, but if dynamic is the only option then so what. If you can solve the problem using static typing do so. That being said, the DLR does call site caching which means some of the overhead is reduced as the plumbing can be reused in some cases.

提交回复
热议问题