/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/standard/parallel-programming/snippets/cs/result2.cs
33 строки
1 KB
Tom Dykstra
Update snippets for NRT (#28615)
11 мар 2022, 00:02
Не верифицирован
11 мар 2022, 00:02
aff1571
Код
Авторство
О чём код?
using System; using System.Threading.Tasks; public class ResultTwoExample { public static async Task Main() => await Task.Run( () => { DateTime date = DateTime.Now; return date.Hour > 17 ? "evening" : date.Hour > 12 ? "afternoon" : "morning"; }) .ContinueWith( antecedent => { if (antecedent.Status == TaskStatus.RanToCompletion) { Console.WriteLine($"Good {antecedent.Result}!"); Console.WriteLine($"And how are you this fine {antecedent.Result}?"); } else if (antecedent.Status == TaskStatus.Faulted) { Console.WriteLine(antecedent.Exception!.GetBaseException().Message); } }); } // The example displays output like the following: // Good afternoon! // And how are you this fine afternoon?