+ 1

What ist the exact issue in this code?

Is this because n1 not inititalize? //================== var n1; n1 = true; Console.WriteLine(n1);

20th Dec 2017, 5:20 AM
Darshan
2 odpowiedzi
+ 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. 😉
20th Dec 2017, 6:30 AM
Zephyr Koo
Zephyr Koo - avatar
+ 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.
20th Dec 2017, 5:25 AM
Dima Makieiev
Dima Makieiev - avatar