使用lambda来检查一个字符串值是字符串数组或列表中的C# [英] Use lambda to check if an string value is in string array or List in C#

查看:741
本文介绍了使用lambda来检查一个字符串值是字符串数组或列表中的C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的是以下检查数组或列表包含一个值:

I use the followings to check the array or List is Included a value:

string[] Names= { /* */};
string target = "";

if(Array.IndexOf(Names, target) > -1)
  //Do

那么,有没有拉姆达前pression检查吗?

So is there any lambda expression to check it?

推荐答案

你的意思是一个LINQ的方法?

Do you mean a Linq method?

如果如此,有一个:

Names.Contains(target)

请注意,没有必要在这里任何的lambda。

Note there is no need for any lambda here.

这篇关于使用lambda来检查一个字符串值是字符串数组或列表中的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆