Skip to content

Instantly share code, notes, and snippets.

@dasjestyr
Created July 19, 2013 16:24
Show Gist options
  • Save dasjestyr/6040462 to your computer and use it in GitHub Desktop.
Save dasjestyr/6040462 to your computer and use it in GitHub Desktop.
See if one list is contained within another list. Basically, what this LINQ query does is check every element in the tested list (possessed) to see if one of them matches something in the larger list (required). If every test succeeds, then the result is true;
public class ListMatcher
{
public bool MeetsRequirements(IEnumerable<string> required, IEnumerable<string> possessed)
{
//possessed = new List<string> { "a", "b", "d", "g" };
//required = new List<string> { "b", "c" };
var meetsRequirements = required.All(r => possessed.Contains(r)); // false
return meetsRequirements;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment