Bird
Raised Fist0

Which of the following is the correct syntax to create a new StringBuilder instance?

easy📝 Syntax Q3 of Q15
C Sharp (C#) - Strings and StringBuilder
Which of the following is the correct syntax to create a new StringBuilder instance?
Avar sb = new stringBuilder();
Bvar sb = StringBuilder();
CStringBuilder sb = new String();
Dvar sb = new StringBuilder();
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct class instantiation syntax in C#

    Use 'new' keyword with exact class name and parentheses.
  2. Step 2: Check each option

    var sb = new StringBuilder(); uses correct casing and syntax; others have errors like missing 'new', wrong class name, or wrong casing.
  3. Final Answer:

    var sb = new StringBuilder(); -> Option D
  4. Quick Check:

    Correct instantiation = var sb = new StringBuilder(); [OK]
Quick Trick: Use 'new StringBuilder()' with exact casing [OK]
Common Mistakes:
MISTAKES
  • Omitting 'new' keyword
  • Using wrong casing for StringBuilder
  • Assigning StringBuilder to string type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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