Linq to object 技巧、用法集锦

一、一个字符串,一个字符串数组。判断字符串数组里的元素出现在字符串中的有几个。

    class Program
    {
        static void Main(string[] args)
        {
            string str = "你在他乡还好吗?";
            string[] WordList = new string[] {"他乡","家庭","还好","怎么" };
            int count = WordList.Where(m => str.Contains(m)).Count();

            Console.WriteLine(count);   //输出2

            Console.ReadKey();
        }
    }
原文地址:https://www.cnblogs.com/kissdodog/p/3133704.html