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