+ 1
What ist the exact issue in this code?
Is this because n1 not inititalize? //================== var n1; n1 = true; Console.WriteLine(n1);
2 Answers
+ 9
Yes. C# is strongly-typed and the usage of var is just a syntactic sugar over conventional data types.
Therefore the value must be initialized which allows the compiler to infer its data type upfront. đ
+ 4
If you use var as a type of variable, you need to initialize it to provide info for a compiler what type you meant. For example var a = someObject.method(); return type may have a long name, and you are replacing it with var.