Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new StringBuilder object.
C Sharp (C#)
var sb = new [1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'String' instead of 'StringBuilder' because strings are immutable.
Trying to use a non-existent class like 'StringBuilderBuilder'.
✗ Incorrect
The StringBuilder class is used to create a mutable string object in C#. You create it by calling new StringBuilder().
2fill in blank
mediumComplete the code to append text to the StringBuilder.
C Sharp (C#)
sb.[1]("Hello");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Add' which does not exist for StringBuilder.
Using 'Concat' which is a string method, not StringBuilder.
✗ Incorrect
The Append method adds text to the end of the current StringBuilder content.
3fill in blank
hardFix the error in the code to convert StringBuilder to string.
C Sharp (C#)
string result = sb.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'toString' which causes a compile error.
Trying to use 'Convert' or 'Stringify' which do not exist.
✗ Incorrect
The correct method to convert a StringBuilder to a string is ToString() with capital 'T' and 'S'.
4fill in blank
hardFill both blanks to create a StringBuilder and append text.
C Sharp (C#)
var sb = new [1](); sb.[2]("World");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'String' instead of 'StringBuilder' for the object.
Using 'Add' instead of 'Append' to add text.
✗ Incorrect
You create a StringBuilder object and then use Append to add text.
5fill in blank
hardFill all three blanks to create a StringBuilder, append text, and convert to string.
C Sharp (C#)
var sb = new [1](); sb.[2]("Hello "); sb.[3]("World"); string result = sb.ToString();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Add' which is not a StringBuilder method.
Using 'Insert' which inserts at a position, not appends.
✗ Incorrect
Create a StringBuilder, then use Append twice to add text pieces.