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