ITPub博客

首页 > IT职业 > IT图书 > Lambda表达式where过滤数据

Lambda表达式where过滤数据

IT图书 作者:shinez 时间:2021-09-09 09:44:17 0 删除 编辑

使用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

 

运行结果:

图片描述

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3127/viewspace-2806691/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-30

  • 博文量
    0
  • 访问量
    932