Difference between Var and Dynamics in C#

CsharpProgrammingServer Side Programming

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

Published on 17-Sep-2018 17:35:30