โ Back to Exceptions
Question 663
Null Reference Exception
Null Reference Exception
A variabletextstarts asnull. Read an integercmd; ifcmd == 1, settext = "hello". Then printLength: <text.Length>. Iftextis still null, accessing.Lengththrows aNullReferenceException; catch it and printText was null. Use top-level statements withtry/catch. Input1prints: Length: 5 Input0prints: Text was null
Expected Output:
Length: 5
Topics:
Exceptions
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.