Bird
Raised Fist0

What will be the output of this C# code?

medium📝 Predict Output Q5 of Q15
C Sharp (C#) - Strings and StringBuilder
What will be the output of this C# code?
string part1 = "code";
string part2 = part1 + "123";
Console.WriteLine(part2.Length);
A3
B6
C4
D7
Step-by-Step Solution
Solution:
  1. Step 1: Analyze string concatenation

    part1 is "code" (length 4), concatenated with "123" (length 3).
  2. Step 2: Calculate total length

    Combined string is "code123" with length 7.
  3. Final Answer:

    7 -> Option D
  4. Quick Check:

    Sum lengths of concatenated strings [OK]
Quick Trick: Add lengths of concatenated strings [OK]
Common Mistakes:
MISTAKES
  • Counting only one string's length
  • Confusing characters with string length
  • Ignoring concatenation effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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