Using LINQ extension method syntax on a MatchCollection

前端 未结 6 1263
逝去的感伤
逝去的感伤 2020-12-13 01:20

I have the following code:

MatchCollection matches = myRegEx.Matches(content);

bool result = (from Match m in matches
               where m.Groups["nam         


        
6条回答
  •  难免孤独
    2020-12-13 01:49

    EDIT:

     public static IEnumerable AsEnumerable(this IEnumerable enumerable)
     {
          foreach(object item in enumerable)
              yield return (T)item;
     }
    

    Then you should be able to call this extension method to turn it into an IEnumerable:

     matches.AsEnumerable().Any(x => x.Groups["name"].Value.Length > 128);
    

提交回复
热议问题