As I was messing with tasks, I made a private static async method that returns a random number after a delay. I had also made a public static method that calls the private static async method, but I had forgotten to change the return type from Task
to Task<int>
.
public static Task GetRandomNumber()
{
return GetRandomNumberAsync();
}
private static async Task<int> GetRandomNumberAsync()
{
await Task.Delay(2000);
var rnd = new Random();
return rnd.Next();
}
Is this just some shorthand version at work? If not, does that mean you can always return a derived class if the base class is expected?