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

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -