简体   繁体   English

这个语法是什么意思? FUNC <Task, TResult> sampleFunction

[英]What does this syntax mean? Func<Task, TResult> sampleFunction

I have been using Task.Factory.ContinueWhenAny() for while and just decided to examine other options. 我一直在使用Task.Factory.ContinueWhenAny() ,只是决定检查其他选项。 So I referred to it's MSDN reference page and the syntax for this commands is described as: 所以我提到了它的MSDN参考页面,这个命令的语法描述如下:

public Task<TResult> ContinueWhenAny<TResult>(
    Task[] tasks,
    Func<Task, TResult> continuationFunction,
    CancellationToken cancellationToken
)

It's clear to me that the parts mentioned inside < & > are types , such as the expected return value of a type TResult in Task<TResult> . 很明显,我认为内提到的份<>类型 ,例如,如上所述类型的预期的返回值TResultTask<TResult> However I am not quite sure what this part of this syntax would mean: 但是我不太确定这个语法的这一部分是什么意思:

Func<Task, TResult> continuationFunction

As you can see there are two parameters sandwiched inside <> and separated by a comma. 如您所见,有两个参数夹在<>并用逗号分隔。

It's a Func delegate and it's declared like this: 它是一个Func委托,它的声明如下:

public delegate TResult Func<in T, out TResult>(T arg);

It represents a function that takes a Task parameter and returns a result of type TResult . 它表示一个函数,它接受一个Task参数并返回一个TResult类型的结果。

It is similar to: 它类似于:

TResult ContinuationFunction<T,TResult>(T arg) { ... }

Further reading 进一步阅读

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM