AnonymousDelegate help for c#

41 Views Asked by At

I need help with this

ParallelOptions parallelOption = new ParallelOptions()
{
    MaxDegreeOfParallelism = 1000
};
Parallel.ForEach<string>(strs, parallelOption, (string a0, ParallelLoopState a1, long a2)
     => new VB$AnonymousDelegate_0<string, ParallelLoopState, long, object>((string url, ParallelLoopState i, long j) 
     => {

VB$AnonymousDelegate_0< is giving me an error

1

There are 1 best solutions below

0
jdphenix On

You're using a lambda in a place where the compiler should be able to infer types.

So, you should be able to do

Parallel.ForEach(
    strs, 
    parallelOption
    (s, state, i) => {
        // lambda body
    });

without any other work. The type of s will be inferred from the type of strs, and the other two types will be inferred by overload resolution finding the Parallel.ForEach call.

Related link