1
首先,我知道这是this question的副本,但我无法获得列出的解决方案为我工作。我明白,MatchCollection没有实现IEnumerable Parallel.ForEach用法,因此需要OfType()...任何想法我做错了什么?这里是我的设置:Parallel.ForEach with MatchCollection
MatchCollection startMatches = Regex.Matches(tempRTB.Text, startPattern);
System.Threading.Tasks.Parallel.ForEach(startMatches.OfType<Match>, m =>
{
// do stuff with m
});
而这里的编译错误,我得到:
Error 11 The type arguments for method 'System.Threading.Tasks.Parallel.ForEach<TSource>(System.Collections.Generic.IEnumerable<TSource>, System.Action<TSource>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
注意'MatchCollection ''元素总是'匹配',所以你可以使用'.Cast()'而不是'OfType'。 –
2013-05-13 18:10:24