Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q13 of 15
C Sharp (C#) - Strings and StringBuilder
What is the output of the following code?
int x = 5;
int y = 3;
string result = $"Sum: {x + y}, Product: {x * y}";
Console.WriteLine(result);
ASum: 53, Product: 15
BSum: {x + y}, Product: {x * y}
CSum: 8, Product: 15
DSum: 8 Product: 15
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate expressions inside interpolation

    The expressions {x + y} and {x * y} calculate 5 + 3 = 8 and 5 * 3 = 15 respectively.
  2. Step 2: Check output formatting

    The string inserts these values with a comma and space exactly as written, so output is "Sum: 8, Product: 15".
  3. Final Answer:

    Sum: 8, Product: 15 -> Option C
  4. Quick Check:

    Expressions inside {} are evaluated before output [OK]
Quick Trick: Calculate expressions inside {} before output [OK]
Common Mistakes:
MISTAKES
  • Thinking expressions print literally
  • Concatenating numbers as strings
  • Missing commas or spaces in output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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