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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

245 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements