C# 平行。用于步长
有人知道是否有任何重载允许我在Parallel.For循环中指定步长吗?c#或VB.Net中的示例都很好 感谢Gonzalo的“enumerable.range step”,您应该能够找到enumerable.range提供阶梯式范围的替代实现。然后你就可以做一个C# 平行。用于步长,c#,.net,vb.net,parallel-extensions,C#,.net,Vb.net,Parallel Extensions,有人知道是否有任何重载允许我在Parallel.For循环中指定步长吗?c#或VB.Net中的示例都很好 感谢Gonzalo的“enumerable.range step”,您应该能够找到enumerable.range提供阶梯式范围的替代实现。然后你就可以做一个 Parallel.ForEach(BetterEnumerable.SteppedRange(fromInclusive, toExclusive, step), ...) 如果谷歌不工作,实现应该是这样的: public stat
Parallel.ForEach(BetterEnumerable.SteppedRange(fromInclusive, toExclusive, step), ...)
如果谷歌不工作,实现应该是这样的:
public static class BetterEnumerable {
public static IEnumerable<int> SteppedRange(int fromInclusive, int toExclusive, int step) {
for (var i = fromInclusive; i < toExclusive; i += step) {
yield return i;
}
}
}
公共静态类BetterEnumerable{
公共静态IEnumerable SpideDrange(int-fromInclusive、int-toExclusive、int-step){
for(var i=from inclusive;i
或者,如果“收益率回报”给出了一个heebie jeebies,您可以随时创建一个常规的旧列表:
var list = new List<int>();
for (int i = fromInclusive; i < toExclusive; i += step) {
list.Add(i);
}
Parallel.ForEach(list, ...);
var list=newlist();
for(int i=from inclusive;i
如果需要的话,这应该很容易翻译成VB。谢谢Dax。如果我在没有收益回报的VB.Net中尝试这样做会不会有太多额外的工作?没有VB经验,但您应该能够使用for循环生成包含所需整数的整数列表,然后对该列表使用
Parallel.ForEach
。@Gonzalo:the启用VB.Net中的迭代器。