Bird
0
0

What will be printed by this code?

medium📝 Predict Output Q5 of 15
C Sharp (C#) - Strings and StringBuilder
What will be printed by this code?
double price = 12.5;
string output = $"Price: {price:F1}";
Console.WriteLine(output);
APrice: F1
BPrice: 12.50
CPrice: 12.5
DPrice: {price:F1}
Step-by-Step Solution
Solution:
  1. Step 1: Understand :F1 format specifier

    :F1 formats floating number with 1 decimal place.
  2. Step 2: Format price=12.5 with :F1

    12.5 already has one decimal place, so output is "12.5".
  3. Final Answer:

    Price: 12.5 -> Option C
  4. Quick Check:

    :F1 formats float with 1 decimal place [OK]
Quick Trick: Use :F1 to show one decimal place for floats [OK]
Common Mistakes:
MISTAKES
  • Expecting two decimals instead of one
  • Printing format specifier as text

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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