Difference Between var and dynamic

Medium2-4 Years

Both var and dynamic are used to declare variables.

var

  • Compile-time type checking
  • Type inferred by compiler

dynamic

  • Runtime type checking
  • Type resolved during execution

Example

var name = "John";

dynamic value = 10;

value = "Hello";

Interview Tips

var is faster than dynamic.