+ 1
Hi. If anyone help me explain attached example I'll appreciate. It relates using unassigned variables, like in the code. Thanks.
2 Respuestas
+ 4
A is a class level member variable. Class members that have not explicitly been initialized are given default initial values depending on their type. int in this case is given a default value of 0. This is not the case however with local variables. Local variables must be given an explicit initial value prior to attempting to utilize that value.
If you comment out the code in main and instead do a Console.WriteLine(A); you'll see that the value of A is output as 0. If you attempt to do this with the local variable B you'll receive an error because B has not yet been assigned a value.
+ 2
Distinction between local and class member variable proved to be crucial here :) It is now clear in full. Thanks a lot!