簡體   English   中英

與MatchCollection的Parallel.ForEach

[英]Parallel.ForEach with MatchCollection

首先,我知道這是這個問題的重復,但我不能讓那里列出的解決方案為我工作。 我理解MatchCollection沒有實現IEnumerable Parallel.ForEach使用,因而需要OfType()......任何想法我做錯了什么? 這是我的設置:

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.

你所缺少的是() (OfType是一種靜態擴展方法)

System.Threading.Tasks.Parallel.ForEach(startMatches.OfType<Match>(), m =>
        {
            // do stuff with m
        });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM