您的位置:首页 > 其它

LINQ的Any方法

2016-04-12 16:50 288 查看
返回布尔值,判断集合中是否有元素满足某一条件。

IEnumerable<string> str = new List<string> {
"asdf","fgsdfg","tyuiu","ryury","ituyitu"
};

//if (str.Any(x => x.EndsWith("iu")))
//{
//    Write("true");
//}
//else
//{
//    Write("false");
//}

bool blnResult = str.Any();

blnResult = str.Any<string>((s) =>
{
return s.LastIndexOf("iu") > 0;
});

if (blnResult)
{
Write("true");
}
else
{
Write("false");
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: