Bird
0
0

Identify the error in this code:

medium📝 Debug Q6 of 15
C Sharp (C#) - Strings and StringBuilder
Identify the error in this code:
int value = 10;
string text = $"Value is {value:Z2}";
Console.WriteLine(text);
AMissing $ before string
BInvalid format specifier 'Z2'
CBraces missing around variable
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check format specifier 'Z2'

    'Z2' is not a valid numeric format in C#.
  2. Step 2: Confirm other syntax

    $ is present and braces are correct, so no other errors.
  3. Final Answer:

    Invalid format specifier 'Z2' -> Option B
  4. Quick Check:

    Format specifiers must be valid standard or custom codes [OK]
Quick Trick: Use only valid format specifiers like D, F, N [OK]
Common Mistakes:
MISTAKES
  • Using unsupported format codes
  • Confusing format specifier syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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