C#-Linq学习笔记-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();
        }
    }
posted @ 2015-05-31 20:11  Dynamics365峰  阅读(103)  评论(0编辑  收藏  举报