+ 1
Var Help
var n1; n1 = true; Console.WriteLine(n1); Whys is this False? Or an error?
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.
+ 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.