Bird
0
0

What does the following C# code do?

easy🧠 Conceptual Q11 of 15
C Sharp (C#) - Strings and StringBuilder
What does the following C# code do?
int age = 25;
string message = $"I am {age} years old.";
AConcatenates the string and integer without formatting.
BInserts the value of <code>age</code> into the string at the placeholder.
CCauses a syntax error because of the dollar sign.
DCreates a string with the text including curly braces literally.
Step-by-Step Solution
Solution:
  1. Step 1: Understand string interpolation syntax

    The dollar sign $ before the string allows inserting variables inside curly braces.
  2. Step 2: Identify variable insertion

    The variable age is inserted where {age} appears, replacing the placeholder with its value.
  3. Final Answer:

    Inserts the value of age into the string at the placeholder. -> Option B
  4. Quick Check:

    String interpolation = Insert variable value [OK]
Quick Trick: Look for $ and {variable} to spot interpolation [OK]
Common Mistakes:
MISTAKES
  • Thinking $ means string concatenation
  • Expecting curly braces to print literally
  • Confusing interpolation with format method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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