Lambda表达式where过滤数据

Posted Insus.NET

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 

运行结果:

 

以上是关于Lambda表达式where过滤数据的主要内容,如果未能解决你的问题,请参考以下文章