December 2018
Beginner to intermediate
668 pages
15h 30m
English
One of the limitations with console applications is that you can only use the await keyword inside methods that are marked as async..., and C# 7 and earlier do not allow the Main method to be marked as async!
Luckily, a new feature in C# 7.1 is support for async on Main.
Create a new console app named AsyncConsole.
Import the System.Net.Http and System.Threading.Tasks namespaces, and statically import System.Console, as shown in the following code:
using System.Net.Http;using System.Threading.Tasks;using static System.Console;
Add statements to the Main method to create an HttpClient instance, make a request for Apple's home page, and output how many bytes it has, as shown in the following code:
Read now
Unlock full access