在MatchCollection使用LINQ扩展方法的语法 [英] Using Linq extension method syntax on MatchCollection
本文介绍了在MatchCollection使用LINQ扩展方法的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
MatchCollection匹配= myRegEx.Matches(内容);
布尔结果=(从场比赛M
其中m.Groups [名称] Value.Length方式> 128
选择M)。任何();
有没有办法做到这一点使用LINQ的扩展方法的语法?事情是这样的..
布尔结果= matches.Any(X => ...);
解决方案
使用系统.Linq;
matches.Cast<比赛方式>()任何(X => x.Groups [名称] Value.Length方式> 128)
您只需要将其从的IEnumerable
转换为的IEnumerable<比赛方式>
(IEnumerable的)以访问提供的IEnumerable的LINQ扩展
I have the following code:
MatchCollection matches = myRegEx.Matches(content);
bool result = (from Match m in matches
where m.Groups["name"].Value.Length > 128
select m).Any();
Is there a way to do this using the Linq extension method syntax? Something like this..
bool result = matches.Any(x => ... );
解决方案
using System.Linq;
matches.Cast<Match>().Any(x => x.Groups["name"].Value.Length > 128)
You just need to convert it from an IEnumerable
to an IEnumerable<Match>
(IEnumerable) to get access to the linq extension provided on IEnumerable.
这篇关于在MatchCollection使用LINQ扩展方法的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文