+ 1

Hi. If anyone help me explain attached example I'll appreciate. It relates using unassigned variables, like in the code. Thanks.

https://code.sololearn.com/cI1Hqlxezy7U/?ref=app

28th Sep 2017, 8:38 PM
p-182-25
p-182-25 - avatar
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.
28th Sep 2017, 8:53 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Distinction between local and class member variable proved to be crucial here :) It is now clear in full. Thanks a lot!
28th Sep 2017, 10:21 PM
p-182-25
p-182-25 - avatar