在C#5.0异步泛型委托 [英] Async generic delegate in C# 5.0

查看:558
本文介绍了在C#5.0异步泛型委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过迭代器,下面的泛型委托是可能的:

With Iterators, the following generic delegate is possible:

public delegate IEnumerable<TOut> MyDelegate<TIn>(TIn param1);

随着新的异步/等待在C#5.0 CTP,我希望能够建立类似的委托如下:

With the new async/await in C# 5.0 CTP, I expect to be able to create the analogous delegate as follows:

public delegate async TOut MyDelegate<TIn>(TIn param1);

我无法找到C#5.0规范或这方面的任何帮助。任何人都知道这可怎么写,或者如果它不能写入,为什么?

I can't find the C# 5.0 spec or any help in this regard. Anyone know how this can be written or if it can't be written and why?

谢谢!

推荐答案

异步是一个实现细节,而不是一个接口规范。一个异步委托没有意义。

async is an implementation detail, not an interface specification. An async delegate doesn't make sense.

这将返回awaitable(如任务任务&LT; T&GT; )的任何方法可以用于与等待

Any method that returns an "awaitable" (such as Task or Task<T>) can be used with await.

因此​​,一个异步委托将是返回任何委托类型工作任务&LT; T&GT; (或任何其他种类的awaitable)。你的情况:

So an "asynchronous delegate" would be any delegate type that returns Task or Task<T> (or any other kind of awaitable). In your case:

public delegate Task<TOut> MyDelegate<TIn, TOut>(TIn param1);

这篇关于在C#5.0异步泛型委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆