Lio Liov
Lio Liov

Reputation: 3

Return false from async Task method

I am using async Task method. Is there any way to return false from this method. If not how can I handle this scenario?

public static async Task Share(MemoryStream streamToEmail)
{
    if(streamToEmail.Length < 10000000)
    {
        await SendEmails();
    }
    else
    {
         //return false;
    }             
}

Upvotes: 0

Views: 304

Answers (1)

sunero4
sunero4

Reputation: 840

Not unless you are planning to also return some boolean in the if-branch. If you do though, you could do it like this:

public static async Task<bool> Share(MemoryStream streamToEmail)
{
    if(streamToEmail.Length < 10000000)
    {
        await SendEmails();
        return true;
    }
    else
    {
         return false;
    }          
}

Upvotes: 2

Related Questions