A Quick KT on dynamic vs. var keyword

The fundamental difference between 'var' and 'dynamic'
- 'var' keyword the type infer at compile time
- 'dynamic' keyword the type infer at run-time. 

'var' keyword is strongly implicitly typed variable and compiler knows type of variable from the initialization.

On mouse hover over the 'dynamic. keyword
 - Represents an object whose operations will be resolved at run-time

On mouse hover over the 'var' keyword
 - Infer type from value assigned to variable

It is not mandatory to assign value to dynamic type varibale but If you don’t initialize 'var' type at the time of declaration then compiler shouting an error
dynamic d_test; //ok
var v_t = "Test"; //ok
var v_k; //compile time error

Note I true believe too much use of dynamic could induce 
1. performance degredation 
2. Increase Runtime Errors possibilites which easyly can be redused at compilte time
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s