Saturday, January 12, 2019

Difference Between var and dynamic in C#


Introduction:-
In this article I will teach you difference between var and dynamic keyword.

Var Dynamic
Var Introduce in C# 3 Dynamic introduce in C# 4
Var is using early binding  Dynamic is using late binding 
Var must need to initialise at the time of declaration No need to initialise at the time of declaration
Check error at compile time Check error at run time
Var will show all data type property after initialising  Dynamic can't show all data type property after initialising 
Example:
var obj="String";
Example:
dynamic obj = "String";

Var :-

  • var it show's all all property based on data type .
  • once you initialise data you can'n modify .
  • var verify datatype property if it's not exist it's throw a compile time error . 








Dynamic :-

  • dynamic is using late binding that why after data initialisation don't what kind of data is 
  • it's through error in run-time if property not exist in appropriate data type . 



Thank's for reading.



No comments:

Post a Comment