How is memory allocated for .net 4.0 dynamic variable?

is dynamic implicit or explicit type distribution? How memory is allocated for dynamic variables in the context of the following example at runtime.

dyanmic impact on type safety since C # is a safe language.

public class Program { static void Main(string[] args) { dynamic dynamicVar = 10; dynamicVar = true; dynamicVar = "hello world"; // compiles fine int index = dynamicVar.IndexOf("world"); } } 
+6
source share
1 answer

A variable of type dynamic is actually a variable of type object with respect to the CLR. This only affects the compiler, which forces any operation using the dynamic expression to go through the runtime binding.

The binding process itself will use additional local variables, etc. (look in ILDASM, Reflector or something similar, and you will be staggered), but from the point of view of dynamicVar , the code you have is a object with the corresponding box for the values ​​of int and bool .

+5
source

Source: https://habr.com/ru/post/953683/


All Articles