비동기 작동 방식을 이해하려고합니다. 내 코드는 다음과 같습니다.키워드 대기 및 게재 방법
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";
}
}
뭐가 잘못 됐나요?
작동? – poke
strReturned 옆에 오류가 있습니다. – Richard77
나는 그것을 보았지만 오류 메시지는 당신이 시도한 것에 무엇이 잘못되었는지를 아주 잘 설명한다. 그래서 무엇을 얻지 못했습니까? – poke