Recall & Review
beginner
What is the main purpose of extension methods in C#?
Extension methods allow you to add new methods to existing types without modifying their source code or creating a new derived type.
Click to reveal answer
beginner
How do extension methods improve code readability?
They let you call new methods as if they were part of the original type, making the code cleaner and easier to understand.Click to reveal answer
beginner
Why can't you always modify existing classes directly to add new methods?
Because the source code might be unavailable, or the class might be sealed or part of a library you don't control.Click to reveal answer
beginner
What is a real-life analogy for extension methods?
It's like adding a new tool to your toolbox without changing the toolbox itself, so you can use the new tool whenever you want.
Click to reveal answer
intermediate
Can extension methods override existing methods of a class?
No, extension methods cannot override existing methods; they only add new methods that appear as if they belong to the type.
Click to reveal answer
Why are extension methods useful in C#?
✗ Incorrect
Extension methods let you add new methods to existing types without modifying their original source code.
Which of these is NOT a reason to use extension methods?
✗ Incorrect
Extension methods cannot modify internal state directly; they only add new methods.
How do you call an extension method in C#?
✗ Incorrect
Extension methods are called like normal instance methods on the type they extend.
Can extension methods access private members of the extended class?
✗ Incorrect
Extension methods cannot access private members; they work only with the public interface.
Which keyword is used to define an extension method?
✗ Incorrect
The 'this' keyword before the first parameter defines the type being extended.
Explain why extension methods are needed and how they help when working with existing classes.
Think about situations where you can't change a class but want to add features.
You got /4 concepts.
Describe a real-life example or analogy that helps understand the concept of extension methods.
Imagine adding something new without breaking what you already have.
You got /3 concepts.