Hello!
Please, could somone make me clear how did they get the result 6?
Why right 6?
many thanks!!!
Please, could somone make me clear how did they get the result 6?
Why right 6?
many thanks!!!
C#:
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600];[/COLOR]
[COLOR=#000088]namespace[/COLOR] [COLOR=#7F0055]StaticVarApplication[/COLOR]
[COLOR=#666600]{[/COLOR]
[COLOR=#000088]class[/COLOR] [COLOR=#7F0055]StaticVar[/COLOR]
[COLOR=#666600]{[/COLOR]
[COLOR=#000088]public[/COLOR] [COLOR=#000088]static[/COLOR] [COLOR=#000088]int[/COLOR] num[COLOR=#666600];[/COLOR]
[COLOR=#000088]public[/COLOR] [COLOR=#000088]void[/COLOR] count[COLOR=#666600]()[/COLOR]
[COLOR=#666600]{[/COLOR]
num[COLOR=#666600]++;[/COLOR]
[COLOR=#666600]}[/COLOR]
[COLOR=#000088]public[/COLOR] [COLOR=#000088]int[/COLOR] getNum[COLOR=#666600]()[/COLOR]
[COLOR=#666600]{[/COLOR]
[COLOR=#000088]return[/COLOR] num[COLOR=#666600];[/COLOR]
[COLOR=#666600]}[/COLOR]
[COLOR=#666600]}[/COLOR]
[COLOR=#000088]class[/COLOR] [COLOR=#7F0055]StaticTester[/COLOR]
[COLOR=#666600]{[/COLOR]
[COLOR=#000088]static[/COLOR] [COLOR=#000088]void[/COLOR] [COLOR=#7F0055]Main[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000088]string[/COLOR][COLOR=#666600][][/COLOR] args[COLOR=#666600])[/COLOR]
[COLOR=#666600]{[/COLOR]
[COLOR=#7F0055]StaticVar[/COLOR] s1 [COLOR=#666600]=[/COLOR] [COLOR=#000088]new[/COLOR] [COLOR=#7F0055]StaticVar[/COLOR][COLOR=#666600]();[/COLOR]
[COLOR=#7F0055]StaticVar[/COLOR] s2 [COLOR=#666600]=[/COLOR] [COLOR=#000088]new[/COLOR] [COLOR=#7F0055]StaticVar[/COLOR][COLOR=#666600]();[/COLOR]
s1[COLOR=#666600].[/COLOR]count[COLOR=#666600]();[/COLOR]
s1[COLOR=#666600].[/COLOR]count[COLOR=#666600]();[/COLOR]
s1[COLOR=#666600].[/COLOR]count[COLOR=#666600]();[/COLOR]
s2[COLOR=#666600].[/COLOR]count[COLOR=#666600]();[/COLOR]
s2[COLOR=#666600].[/COLOR]count[COLOR=#666600]();[/COLOR]
s2[COLOR=#666600].[/COLOR]count[COLOR=#666600]();[/COLOR]
[COLOR=#7F0055]Console[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]WriteLine[/COLOR][COLOR=#666600]([/COLOR][COLOR=#008800]"Variable num for s1: {0}"[/COLOR][COLOR=#666600],[/COLOR] s1[COLOR=#666600].[/COLOR]getNum[COLOR=#666600]());[/COLOR]
[COLOR=#7F0055]Console[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]WriteLine[/COLOR][COLOR=#666600]([/COLOR][COLOR=#008800]"Variable num for s2: {0}"[/COLOR][COLOR=#666600],[/COLOR] s2[COLOR=#666600].[/COLOR]getNum[COLOR=#666600]());[/COLOR]
[COLOR=#7F0055]Console[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]ReadKey[/COLOR][COLOR=#666600]();[/COLOR]
[COLOR=#666600]}[/COLOR]
[COLOR=#666600]}[/COLOR] [COLOR=#666600][FONT=Menlo]}[/FONT][/COLOR]