Complete the code to create a Task that runs a method asynchronously.
Task myTask = Task.[1](() => Console.WriteLine("Hello from Task"));
The Task.Run method is used to start a task that runs asynchronously.
Complete the code to create a Task that returns an integer result asynchronously.
Task<int> myTask = Task.[1](() => 42);
Task.Run can be used with a lambda that returns a value, creating a Task<T>.
Fix the error in the code to await a Task that returns a string.
async Task<string> GetMessageAsync() {
return await [1];
}
Task<string> messageTask = Task.FromResult("Hello");You should await the Task itself, not its Result property or Wait method.
Fill both blanks to create and start a Task that returns the length of a string.
Task<int> lengthTask = new Task<int>(() => [1].Length); lengthTask.[2]();
You create a Task with a lambda using inputString.Length and start it with Start().
Fill all three blanks to create a Task that returns the uppercase version of a string and start it.
Task<string> upperTask = new Task<string>(() => [1].[2]()); upperTask.[3]();
The Task uses input.ToUpper() in the lambda and is started with Start().