为什么C#说CCR的IterativeTask是非泛型的?

发布于 2024-08-02 22:14:45 字数 596 浏览 7 评论 0原文

我正在使用 并发和协调运行时,并且编写的代码类似于文档。以下行无法编译:

yield return new IterativeTask<string,Object,Object,long[]>("Hi",a,b,ls, itfunc);

编译器给出此错误消息:

The non-generic type 'Microsoft.Ccr.Core.IterativeTask' cannot be used with type arguments

这是令人困惑的,因为文档使用带有类型参数的方法,并且它显然是通用的。

(我将在这里发布我自己的答案,即 鼓励

I'm using the Concurrency and Coordination Runtime and am writing code similar to what is described in the documentation. The following line fails to compile:

yield return new IterativeTask<string,Object,Object,long[]>("Hi",a,b,ls, itfunc);

The compiler gives this error message:

The non-generic type 'Microsoft.Ccr.Core.IterativeTask' cannot be used with type arguments

Which is mistifying because the documentation uses that method with type arguments and it's clearly generic.

(I'm going to post my own answer here, that's encouraged as I understand it)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落日海湾 2024-08-09 22:14:45

事实证明,IterativeTask 可以使用的泛型参数数量是有限的:可以使用三个,但不能超过。

因此,这段代码可以编译(一旦您将 itfunc 更改为使用更少的参数):

yield return new IterativeTask<string,Object,long[]>("Hi",a,ls, itfunc);

如果您确实需要参数中的所有信息,则可以创建某种类型来保存它们:

struct Z {
  string msg;
  Object one;
  Object two;
  long[] ls;
}

Z z = new Z { msg="Hi", one=a, two=b, ls= longs };
yield return new IterativeTask<Z>(z, itfunc);

It turns out that there is a limit to the number of generic parameters one can use with IterativeTask: it can take three but no more.

So, this code compiles (once you change itfunc to use one fewer argument):

yield return new IterativeTask<string,Object,long[]>("Hi",a,ls, itfunc);

If you really do need all the information in the arguments, you can create some type to hold them:

struct Z {
  string msg;
  Object one;
  Object two;
  long[] ls;
}

Z z = new Z { msg="Hi", one=a, two=b, ls= longs };
yield return new IterativeTask<Z>(z, itfunc);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文