Bird
Raised Fist0

Which of the following is the correct syntax to insert "Hello" at index 2 in a StringBuilder named sb?

easy📝 Syntax Q3 of Q15
C Sharp (C#) - Strings and StringBuilder
Which of the following is the correct syntax to insert "Hello" at index 2 in a StringBuilder named sb?
Asb.Put(2, "Hello");
Bsb.Add(2, "Hello");
Csb.AppendAt(2, "Hello");
Dsb.Insert(2, "Hello");
Step-by-Step Solution
Solution:
  1. Step 1: Recall StringBuilder insertion method

    The method to insert text at a specific index is Insert.
  2. Step 2: Verify syntax correctness

    The correct syntax is sb.Insert(2, "Hello");. Other methods like Add, AppendAt, or Put do not exist.
  3. Final Answer:

    sb.Insert(2, "Hello"); -> Option D
  4. Quick Check:

    Insert method syntax = sb.Insert(index, string) [OK]
Quick Trick: Use Insert(index, string) to add text at any position [OK]
Common Mistakes:
MISTAKES
  • Using non-existent methods like Add or Put
  • Confusing Append with Insert

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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