+ 1

Var Help

var n1; n1 = true; Console.WriteLine(n1); Whys is this False? Or an error?

24th May 2017, 4:28 AM
ThisIsMyName
2 Respostas
+ 7
You have to assign a value to the variable when you create a variable with the var keyword. Why? Lettme ask you: What datatype am I using for x int x; pretty easy to guess right? Now... What datatype am I using for y? var y; Can you guess it? Probably not unless you continuing reading on my code but sadly machines, when gets confused, stucks on a line of code and gives errors.
24th May 2017, 6:21 AM
Wen Qin
Wen Qin - avatar
+ 4
You have to initialize the variable at the time of declaration using "var" keyword. That way, the compiler can infer the variable's data type.
24th May 2017, 4:33 AM
Bàng Tứ Cường
Bàng Tứ Cường - avatar