Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. So I referred to it's MSDN reference page and the syntax for this commands is described as:

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>. 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.

like image 388
Mehrad Avatar asked Apr 18 '26 18:04

Mehrad


1 Answers

It's a Func delegate and it's declared like this:

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.

It is similar to:

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

Further reading

  • Generics
  • Delegates
  • Func<T, TResult> Delegate
like image 81
Selman Genç Avatar answered Apr 20 '26 07:04

Selman Genç