gpt4 book ai didi

c# - Parallel.For 具有 64 位无符号索引 (UInt64)

转载 作者:行者123 更新时间:2023-11-30 22:42:42 24 4
gpt4 key购买 nike

在 C# 中,有一个 System.Threading.Tasks.Parallel.For(...)这与 for 相同循环,没有顺序,但在多个线程中。问题是,它只适用于 longint , 我想与 ulong 一起工作.好的,我可以进行类型转换,但我在边框方面遇到了一些问题。

比方说,我想要一个来自 long.MaxValue-10 的循环至 long.MaxValue+10 (记住,我说的是 ulong )。我该怎么做?

一个例子:

for (long i = long.MaxValue - 10; i < long.MaxValue; ++i)
{
Console.WriteLine(i);
}
//does the same as
System.Threading.Tasks.Parallel.For(long.MaxValue - 10, long.MaxValue, delegate(long i)
{
Console.WriteLine(i);
});
//except for the order, but theres no equivalent for
long max = long.MaxValue;
for (ulong i = (ulong)max - 10; i < (ulong)max + 10; ++i)
{
Console.WriteLine(i);
}

最佳答案

您可以随时写信给 Microsoft 并要求他们将 Parallel.For(ulong, ulong, Action ) 添加到下一版本的 .NET Framework 中。在此之前,您将不得不求助于这样的事情:

Parallel.For(-10L, 10L, x => { var index = long.MaxValue + (ulong) x; });

关于c# - Parallel.For 具有 64 位无符号索引 (UInt64),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4280074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com