Thursday, November 12, 2015

var Keyword

Defining a variable as var enables to assign any data type value. var is implicit data type declaration.
var str = "hello";

var num = 10;

var is statically defined: Compiler checks assigned value to var and create data type accordingly at the declaration (compile time)
var num = 10; //compiler creates num as int at this declaration
var str = "hello"//compiler creates str as string at this declaration

var is strongly typed: At declaration compiler create appropriate data type by checking assigned value so from next statement of declaration variable behaves like strongly typed variable
str++ //error because its now string
num++ //allowed because its now int
intellisense showing all prop/methods of string for 'str'


object dynamic can also be used but these both resolved at run time. They are dynamically defined and not strongly typed.

No comments:

Post a Comment

CI/CD - Safe DB Changes/Migrations

Safe DB Migrations means updating your database schema without breaking the running application and without downtime . In real systems (A...