Exercise: Implement Your Own Any Method

Reinvent the wheel to better understand the Any method.

We'll cover the following

Write a HasAny method

Now, it’s your turn!

Many of us have heard the phrase “Don’t reinvent the wheel”—meaning that we shouldn’t waste time recreating something that’s already been done. But, to better understand the Any method and practice extension methods, we’re going to do just that. Let’s write our Any method and call it HasAny. For this exercise, don’t use the real Any method.

To complete this exercise, follow the instructions in the comments. Fill in the body of the HasAny method in the EnumerableExtensions.cs file.

Get hands-on with 1200+ tech skills courses.