문제

I've been trying to search about what I can do for my Parallel.ForEach loop:

        selection.Words is Microsoft.Office.Interop.Word.Selection;
        //range is supposed to be a word.Range
        Parallel.ForEach(selection.Words, range =>
        {

        });

This is the error I am receiving, The type arguments for method "System.Threading.Tasks.Parallel.ForEach(System.Collections.Concurrent.OrderablePartitioner, System.Action)' cannot be inferred from the usage. Try specifying the type arguments explicitly."

I've been looking for a good time now, but all of them just show object.AsEnumerable() as the answer. selection.Words cannot be made into an enumberable, however.

도움이 되었습니까?

해결책

You can see that the Words type is a non-generic enumerable -- so the compiler can't infer the generic type parameter for ForEach<TSource>. You could make the collection into a typed generic collection by using OfType<Range>:

Parallel.ForEach(selection.Words.OfType<Microsoft.Office.Interop.Word.Range>(), range =>
    {

    });

다른 팁

Have you tried specifying the type explicitly like this.

var list = new List<string>();
Parallel.ForEach<string>(list, (s) => s.Trim());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top