Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q4 of 15
C Sharp (C#) - Strings and StringBuilder
What is the output of the following code?
int count = 3;
string message = $"Count: {count:D4}";
Console.WriteLine(message);
ACount: {count:D4}
BCount: 0003
CCount: D4
DCount: 3
Step-by-Step Solution
Solution:
  1. Step 1: Understand format specifier :D4

    :D4 formats integer with at least 4 digits, padding with zeros.
  2. Step 2: Apply formatting to count=3

    3 becomes 0003 with :D4 format.
  3. Final Answer:

    Count: 0003 -> Option B
  4. Quick Check:

    Integer :D4 pads with zeros to 4 digits [OK]
Quick Trick: Use :D4 to pad integers with zeros to 4 digits [OK]
Common Mistakes:
MISTAKES
  • Ignoring format specifier and printing raw number
  • Confusing :D4 with string literal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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