Difference between Var and Dynamics in C#



Var is strictly typed in C#, whereas dynamic is not strictly typed.

Var declaration

var a = 10;

Dynamic declaration

dynamic a = 10;

A Var is an implicitly typed variable, but it will not bypass the compile time errors.

Example of var in C#

var a = 10;
a = "Demo"; //  gives compile error

Example of dynamics in C#

dynamic a = 10;
a = "Demo";  // won't give error
Updated on: 2019-07-30T22:30:23+05:30

346 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements