-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
In the example, the entry point's signature "static async Task Main()" is only available for c# v7.1 and above.
Visual Studio defaults to the major version which at time of writing is only 7.0 and most users will get a compilation error, unless they modify the advanced build properties to change the c# version. Is this asking too much of someone trying to learn the framework?
For those using C# 7.0 the main method would look more like this:
static void Main()
{
ReadCharacters().Wait();
}
Note: there's appears to be conflicting opinions on using Wait() vs GetAwaitor().GetResult(). The documentation for GetAwaiter states it is for compiler use only, but I've seen discussions suggesting it should be used: https://stackoverflow.com/questions/17284517/is-task-result-the-same-as-getawaiter-getresult
BTW C# 7.1 and above use GetAwaitor().GetResult() - it generates code which replaces and wraps the async entry point with GetAwaitor().GetResult().
public static void Main(string[] args) =>
private static async Task
https://blogs.msdn.microsoft.com/mazhou/2017/05/30/c-7-series-part-2-async-main/
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: aa3850da-1adf-a7e9-4c64-5d8327839798
- Version Independent ID: 167ba859-4b1e-eaa4-8d9a-c2e695583187
- Content: StreamReader.ReadLineAsync Method (System.IO)
- Content Source: xml/System.IO/StreamReader.xml
- Product: dotnet-api
- GitHub Login: @dotnet-bot
- Microsoft Alias: dotnetcontent