Recall & Review
beginner
What is an extension method in C#?
An extension method is a special kind of static method that allows 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 enable LINQ to work on collections?
LINQ uses extension methods to add query methods like
Where and Select to any collection that implements IEnumerable<T>, allowing queries to be written directly on those collections.Click to reveal answer
intermediate
Why can't LINQ methods be instance methods on collections?
Because collections like arrays or lists are defined in .NET libraries, we cannot change their code to add new instance methods. Extension methods let LINQ add query capabilities without modifying these types.Click to reveal answer
beginner
What is the benefit of LINQ using extension methods for queries?
It allows LINQ to provide a consistent, readable query syntax on many different data sources without changing their original classes, making code easier to write and understand.
Click to reveal answer
intermediate
How does the compiler treat extension methods when you call them?
The compiler translates calls to extension methods as if they were static method calls, passing the instance as the first argument, enabling seamless syntax that looks like instance method calls.
Click to reveal answer
Why does LINQ use extension methods?
✗ Incorrect
LINQ uses extension methods to add query capabilities to existing types like IEnumerable without changing their original code.
Which interface must a collection implement to use LINQ extension methods?
✗ Incorrect
LINQ extension methods work on collections that implement IEnumerable.
What does the compiler do when you call an extension method?
✗ Incorrect
The compiler converts extension method calls into static method calls with the instance as the first argument.
Can you add instance methods directly to existing .NET collection classes?
✗ Incorrect
Existing .NET collection classes cannot be changed directly, so extension methods are used instead.
What is a key advantage of LINQ using extension methods?
✗ Incorrect
Extension methods let LINQ provide a uniform query syntax across different data sources.
Explain why LINQ depends on extension methods to add query capabilities to collections.
Think about how you can add new features to something you cannot change.
You got /4 concepts.
Describe how the compiler handles calls to LINQ extension methods behind the scenes.
Focus on what happens when you write something like collection.Where(...)
You got /4 concepts.