I'm trying to understand how asynchronous works. This is my code:
class Program
{
static void Main(string[] args)
{
Task<string> strReturned = returnStringAsync();
Console.WriteLine("hello!");
string name = await strReturned; //error: The 'await' operator can only be used
//within an async method. Consider marking this
//method with the 'async' modifier and changing
//its return type to 'Task'
Console.WriteLine(name);
}
static async Task<string> returnStringAsync()
{
Thread.Sleep(5000);
return "Richard";
}
}
Any thing wrong?