I am creating an array with the following CreateArray
static method:
public static int[] CreateArray(int size)
{
var ret = new int[size];
ret[0] = 0;
ret[1] = 1;
Parallel.ForEach(Enumerable.Range(2, size - 2), i =>
{
ret[i] = Func(i).Count();
});
return ret;
}
Where Func looks like:
public static IEnumerable<int> Func(int i)
{
...
}
Is it possible to refactor the CreateArray
method in something like:
public static int[] CreateArray(int size)
{
var tableFromIndex2 = ...
return new[] { 0, 1 }
.Concat(tableFromIndex2)
.ToArray();
}
I think PLINQ could be useful here:
var tableFromIndex = ParallelEnumerable.Range(2, size - 2)
.AsOrdered()
.Select(i => Func(i).Count());
return new[] { 0, 1 }
.Concat(tableFromIndex)
.ToArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With