Bird
Raised Fist0

Which of the following is the correct way to create a StringBuilder instance in C#?

easy📝 Syntax Q12 of Q15
C Sharp (C#) - Strings and StringBuilder
Which of the following is the correct way to create a StringBuilder instance in C#?
AStringBuilder sb = new String();
BStringBuilder sb = StringBuilder();
CStringBuilder sb = new stringbuilder();
DStringBuilder sb = new StringBuilder();
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct syntax for creating objects in C#

    Use the 'new' keyword followed by the class name with parentheses.
  2. Step 2: Check each option

    StringBuilder sb = new StringBuilder(); uses 'new StringBuilder()' correctly; others have syntax errors or wrong class names.
  3. Final Answer:

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

    Correct object creation uses 'new ClassName()' = C [OK]
Quick Trick: Use 'new' keyword with exact class name and parentheses [OK]
Common Mistakes:
MISTAKES
  • Omitting 'new' keyword
  • Using lowercase class names
  • Confusing StringBuilder with String

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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