Recall & Review
beginner
What does it mean that strings are immutable in C#?
It means once a string is created, it cannot be changed. Any modification creates a new string instead of changing the original.
Click to reveal answer
beginner
How do you create a new string by changing part of an existing string?
You create a new string by using methods like Replace, Substring, or concatenation. The original string stays the same.
Click to reveal answer
intermediate
Why is string immutability useful in programming?
It helps avoid unexpected changes, makes programs safer, and allows strings to be shared safely across different parts of a program.
Click to reveal answer
intermediate
What happens in memory when you modify a string in C#?
A new string object is created in memory with the changes, and the old string remains unchanged until garbage collected.
Click to reveal answer
beginner
Which C# type is immutable: String or StringBuilder?
String is immutable, while StringBuilder is mutable and allows changes without creating new objects.
Click to reveal answer
What happens when you call Replace on a string in C#?
✗ Incorrect
Calling Replace returns a new string with changes; the original string stays the same.
Why are strings immutable in C#?
✗ Incorrect
Immutability helps avoid bugs and allows safe sharing of strings.
Which type should you use for many string changes to improve performance?
✗ Incorrect
StringBuilder allows efficient modifications without creating new strings each time.
If you do this: string s = "cat"; s += "s"; what happens?
✗ Incorrect
The += operator creates a new string and assigns it to s.
Which statement is true about string immutability?
✗ Incorrect
Strings in C# are immutable, meaning they cannot be changed after creation.
Explain what string immutability means and why it is important in C#.
Think about how changing a string actually works behind the scenes.
You got /4 concepts.
Describe the difference between String and StringBuilder in terms of mutability.
Consider performance when changing strings many times.
You got /4 concepts.