c# - How to initialize large array parallel with PLINQ? -


i trying initialize simple (but large) array, using plinq:

void test(int width, int height) {     var foo = new foo[width * height];     foo.asparallel().forall(c => new foo()); } 

but leave me array of width x height null (uninitialized) elements.

surely must possible since operation can paralyzed(?).

what correct syntax perform initialization plinq?

i don't doubt there way initialize array linq in parallel, but, i'd suggest using parallel.for instead:

var foo = new foo[width * height]; parallel.for(0, foo.length, => foo[i] = new foo()); 

edit: since want proper plinq solution (also, fixed typo pointed out):

var foo = enumerable.range(0, width * height)                     .asparallel()                     .select(x => new foo())                     .toarray(); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -