0
0
C Sharp (C#)programming~10 mins

StringBuilder methods and performance in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to append a string to the StringBuilder.

C Sharp (C#)
var sb = new StringBuilder();
sb.[1]("Hello");
Console.WriteLine(sb.ToString());
Drag options to blanks, or click blank then click option'
AAdd
BInsert
CConcat
DAppend
Attempts:
3 left
💡 Hint
Common Mistakes
Using Add which does not exist for StringBuilder.
Using Concat which is a string method, not StringBuilder.
Using Insert which adds text at a specific position, not at the end.
2fill in blank
medium

Complete the code to insert a string at the beginning of the StringBuilder.

C Sharp (C#)
var sb = new StringBuilder("World");
sb.[1](0, "Hello ");
Console.WriteLine(sb.ToString());
Drag options to blanks, or click blank then click option'
AInsert
BAppend
CReplace
DRemove
Attempts:
3 left
💡 Hint
Common Mistakes
Using Append which adds text only at the end.
Using Replace which changes existing text.
Using Remove which deletes text.
3fill in blank
hard

Fix the error in the code to remove 5 characters starting at index 6.

C Sharp (C#)
var sb = new StringBuilder("Hello, World!");
sb.[1](6, 5);
Console.WriteLine(sb.ToString());
Drag options to blanks, or click blank then click option'
ADelete
BRemove
CCut
DErase
Attempts:
3 left
💡 Hint
Common Mistakes
Using Delete which does not exist in StringBuilder.
Using Cut or Erase which are not valid methods.
4fill in blank
hard

Fill both blanks to replace 'World' with 'C#' in the StringBuilder.

C Sharp (C#)
var sb = new StringBuilder("Hello, World!");
sb.[1]("World", [2]);
Console.WriteLine(sb.ToString());
Drag options to blanks, or click blank then click option'
A"C#"
BReplace
C"Java"
DRemove
Attempts:
3 left
💡 Hint
Common Mistakes
Using Remove which deletes text but does not replace.
Swapping the order of method and replacement string.
5fill in blank
hard

Fill all three blanks to create a StringBuilder, append 'Hello', insert 'C# ', and remove 1 character at index 5.

C Sharp (C#)
var sb = new [1]();
sb.[2]("Hello");
sb.[3](0, "C# ");
sb.Remove(5, 1);
Console.WriteLine(sb.ToString());
Drag options to blanks, or click blank then click option'
AStringBuilder
BAppend
CInsert
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using String instead of StringBuilder for the object.
Mixing up Append and Insert methods.