Bird
0
0

What will be the output of this C# code?

medium📝 Predict Output Q5 of 15
C Sharp (C#) - Exception Handling
What will be the output of this C# code?
try { string s = null; Console.WriteLine(s.Length); } catch (NullReferenceException) { Console.WriteLine("Null reference error caught"); }
ANull reference error caught
B0
CRuntime error without message
DEmpty line
Step-by-Step Solution
Solution:
  1. Step 1: Understand null reference access

    Accessing Length on a null string causes NullReferenceException.
  2. Step 2: Catch block output

    The catch block prints "Null reference error caught" when exception occurs.
  3. Final Answer:

    Null reference error caught -> Option A
  4. Quick Check:

    Null reference exception handled = B [OK]
Quick Trick: Null object access triggers NullReferenceException catch [OK]
Common Mistakes:
MISTAKES
  • Expecting zero output
  • Ignoring exception handling
  • Assuming program crashes silently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes