Check list contains the values of another list
Following example returns the list contains the values of another list
using System; using System.Collections.Generic; using System.Linq; namespace ZeroToCSharp { class Program { static void Main(string[] args) { string[] filter = new string[] { "Ape", "Bird", "Cat", "Dolphin", "Eagle" }; List<string> animals = new List<string>() { "Bison", "Ape", "Pony", "Ape", "Monkey", "Deer", "Cat", "Cow" }; var result = animals.Where(x => filter.Contains(x)).ToList(); //To print output result.ForEach(x => Console.WriteLine(x)); Console.ReadKey(); } } }
Output:
Ape
Ape
Cat
Subscribe
0 Comments