Salam Alikom ,
I think that most of developers are using “var” and “dynamic” data types and they think that the two data types has the same function !? , maybe that are right ! but when we study each one .. we will find that each one has its own role ! HOW?
if we wrote on Visual Studio:
var x = “Weldo”;
Static Type of x is String & the Runtime Type of x will be String also ! what’s Mean ?
Means that “var” says : Let the Compiler Figure out the Type .
the compiler will assign the variable x string data type before compiling & of course the runtime type will be also string because the compiler decided the type before compiling the source code.
and if we wrote:
dynamic y = “Weldo”;
the Static Type of y will be dynamic & the runtime type of y will be string !
so, “Dynamic” says : Let the Runtime Figure out the Type .
the compiler won’t care about variable y assignment ….
……….. if you understood the idea of “var” and “dynamic” … what are the Error types of the following two lines code ?
int n = x; // x is a var string
int w = y; // y is a dynamic string
-
-
-
-
-
-
-
1. Compile-time Error
2. Runtime Error
Good Luck ![]()
Salam Alikom













