Bird
Raised Fist0

What will be the output of this code snippet?

medium📝 Predict Output Q4 of Q15
C Sharp (C#) - File IO
What will be the output of this code snippet?
using System.Text.Json;

var json = "{\"Age\":30}";
var person = JsonSerializer.Deserialize(json);
Console.WriteLine(person.Age);

Assuming class Person { public int Age { get; set; } }
ACompilation error
B30
Cnull
D0
Step-by-Step Solution
Solution:
  1. Step 1: Deserialize JSON string to Person object

    The JSON string contains Age=30, which matches the Person class property Age.
  2. Step 2: Print the Age property

    After deserialization, person.Age will be 30, so Console.WriteLine outputs 30.
  3. Final Answer:

    30 -> Option B
  4. Quick Check:

    Deserialized Age value = 30 [OK]
Quick Trick: Matching JSON property names deserialize correctly to object properties [OK]
Common Mistakes:
MISTAKES
  • Expecting default 0 instead of 30
  • Confusing null with integer property
  • Assuming compilation error due to missing namespace

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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