为什么C#说CCR的IterativeTask是非泛型的?
我正在使用 并发和协调运行时,并且编写的代码类似于文档。以下行无法编译:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,IterativeTask 可以使用的泛型参数数量是有限的:可以使用三个,但不能超过。
因此,这段代码可以编译(一旦您将 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):
If you really do need all the information in the arguments, you can create some type to hold them: