C# Querying With LINQ Querying the BirdWatcher Data Extension Method

Dan Whiting
Dan Whiting
12,660 Points

Extension method challenge

I may be going about this all wrong. So, I think you need to do something like this:

myList.Where(stringToCheck => stringToCheck.Contains(myString));

My question is where do i get the myString because source has no properties attached to it?

Super confused here.

using System.Collections.Generic;
using System.Linq;

namespace Treehouse.CodeChallenges
    public static class ContainsAnyExtension{

        public static bool ContainsAny(this string source, IEnumerable<string> stringsToMatch){
            if(stringsToMatch.Where(s => source == null || s.Contains(source))){
                return true;

1 Answer

Steven Parker
Steven Parker
155,814 Points

:point_right: You're close, but you have a few issues yet:

  • "Where" returns an IEnumerable — to get a boolean for the if use "Any" instead
  • you probably don't want to return true if the source is null
  • perhaps you meant to check if the source contains the strings (instead of the strings contain the source)
  • you need to return false if a match is not found

The "myString" would be the "s" in your lambda expression.