Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# Querying With LINQ Querying the BirdWatcher Data Extension Method

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.

ContainsAnyExtension.cs
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
231,198 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.