Parallel .ForEach do not like IList

The following code does not compile.

IList configurationItems = dataSourceService.Get(configurationClass);
Parallel.ForEach(configurationItems, configurationItem =>
{...}

Parallel.ForEach complains: “Type arguments for the ForEach (IEnumerable, Action) method cannot be taken out of use. Try explicitly specifying the type arguments.

I have tried all cast forms that I can think of, and none of them work. My attempts to figure out overloads for Parallel.ForEach were also unsuccessful.

+4
source share
1 answer

Can you do ILista IList<T>?

, Parallel.ForEach Parallel.ForEach<T> - . # , . ForEach<T>(IEnumerable<T>, Action<T>). IEnumerable<T>, , T . IList IEnumerable<T>, IEnumerable, , . .

, IList,

Parallel.ForEach<T>(configurationItems.OfType<T>(), (T item) => ....);

T - , .
, ForEach. , . OfType<T>, , , .

+3

All Articles