Wednesday, August 23, 2023

New Video: 'await' Return Types

A new video is available on my YouTube channel: Why do you have to return a Task when you use "await" in a C# method?. The video is a quick walkthrough of code based on an article from earlier this week (link below).

Whenever we "await" something in a C# method, the return value is automatically wrapped in a Task, and the return type for the method must include the Task as well. This leads to some strange looking code: the code in the method returns one thing (such as a Person object), but the return type for the method returns another (a Task of Person). In this video, we will look at some code to try to understand this a bit better.

The code compares using "await" with what happens if we were to use "Task" manually. The comparison helps my brain process the disconnect between return types. Hopefully it will help you as well.


More videos are on the way.

Happy Coding!

No comments:

Post a Comment