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();
        }
    }
复制代码
 
 
 
0
0
 
(请您对文章做出评价)
 
« 上一篇:javascript闭包
» 下一篇:SQL Server索引设计 <第五篇>
原文地址:https://www.cnblogs.com/mingxuantongxue/p/4710093.html