Bird
Raised Fist0

What will be the output of this code?

medium📝 Predict Output Q5 of Q15
C Sharp (C#) - Strings and StringBuilder
What will be the output of this code?
var sb = new System.Text.StringBuilder();
sb.Append("123");
sb.Insert(1, "abc");
Console.WriteLine(sb.ToString());
A123abc
Babc123
C1abc23
D12abc3
Step-by-Step Solution
Solution:
  1. Step 1: Understand Append and Insert effects

    Append("123") creates "123". Insert(1, "abc") inserts "abc" at index 1, between '1' and '2'.
  2. Step 2: Construct final string

    Result is "1" + "abc" + "23" = "1abc23".
  3. Final Answer:

    1abc23 -> Option C
  4. Quick Check:

    Insert adds text at index correctly = 1abc23 [OK]
Quick Trick: Insert shifts existing chars right from index [OK]
Common Mistakes:
MISTAKES
  • Inserting at wrong index
  • Appending instead of inserting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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