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 trialDavid Merk
9,863 PointsI'm really struggling with a challenge. This looks right to me. Last Q in Linq :)
The goal is to see if any of stringsToMatch are in the source, to me that looks like stringsToMatch.Any preceeded by source.Contains, however I'm not having any luck with that.
using System.Collections.Generic;
using System.Linq;
namespace Treehouse.CodeChallenges
{
public static class ContainsAnyExtension
{
public static bool ContainsAny(this string source, IEnumerable<string> stringsToMatch)
{
return stringsToMatch.Any(s => s.Contains(source));
}
}
}
2 Answers
Matthew Hill
7,799 PointsTry using .contains on your source string first ?
Jeff Hamilton
11,724 PointsJust finished it. This is what worked for me.
public static class ContainsAnyExtension {
public static bool ContainsAny(this string source, IEnumerable<string> stringsToMatch) {
return stringsToMatch.Any(item => source.Contains(item));
}
}
David Merk
9,863 PointsDavid Merk
9,863 Pointsreturn source.Contains(stringsToMatch.Any(n => n.?)); Am I getting warmer?