1.var
Type is decided at compile time
Strongly typed
Must be initialized at declaration
IntelliSense & compile-time checking available
Example
var x = 10; // intvar name = "Ram"; // string
👉 If you assign a wrong type later → compile-time error
2.dynamic
Type is decided at runtime
Not strongly typed
No compile-time checking
Errors occur at runtime
Example
dynamic x = 10;x = "Ram"; // allowedx.DoSomething(); // runtime error if method not found
3.Key Differences (Interview Points)
Feature |
var |
dynamic |
|---|---|---|
Type resolution |
Compile time |
Runtime |
Type safety |
Yes |
No |
IntelliSense |
Yes |
No |
Error checking |
Compile time |
Runtime |
Type change allowed |
No |
Yes |
4.When to use?
Use
varwhen type is obvious and you want clean codeUse
dynamicwhen working with:COM objects
Reflection
JSON / loosely typed data
5.Important interview one-liner
varis statically typed,dynamicis dynamically typed.