gpt4 book ai didi

c# - 为什么我们可以使用这样的任务?

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

task.ContinueWith( x => Process(x));

task.ContinueWith( Process)

我想知道为什么两者都可以工作?

我以为ContinueWith至少需要Task的一个参数

最佳答案

正在将 lambda 表达式转换为方法组。

13.6 Method group conversions

Similar to the implicit anonymous method conversions described in §13.5, an implicit conversion existsfrom a method group (§14.1) to a compatible delegate type. If D is adelegate type, and E is an expression that is classified as a methodgroup, then D is compatible with E if and only if E contains at leastone method that is applicable in its normal form (§14.4.2.1) to anyargument list (§14.4.1) having types and modifiers matching theparameter types and modifiers of D.

The compile-time application ofthe conversion from E to D is the same as the compile-time processingof the delegate creation expression new D(E) (§14.5.10.3). Note thatthe existence of an implicit conversion from E to D just indicatesthat the set of applicable methods is not empty, but does notguarantee that the compile-time application of the conversion willsucceed without error.

参见 http://en.csharp-online.net/ECMA-334:_13.6_Method_group_conversions例如。

关于c# - 为什么我们可以使用这样的任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12868717/

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