Lambda表达式where过滤数据

使用Lambda的表达式来过滤符合条件的数据。下面的代码实现,是把字符阵列中,把名字长度等于3元素找出来。

 

class Bv
    {
        public void LambdaExpression()
        {
            string[] names = new string[] { "insus", "leo", "yang", "Joe", "Michael" };

            var result = names.Where(x => x.Length == 3);

            foreach (string s in result)
            {
                Console.WriteLine(s);
            }
        }

    }
Source Code

 

运行结果:

 

posted @ 2017-12-30 16:57  Insus.NET  阅读(4126)  评论(0编辑  收藏  举报