DESAFIO: O que esse código faz?

Qual deveria ser o resultado da execução desse código?

using System;
using System.Threading.Tasks;

using static System.Console;
using static System.IO.File;

class Program
{
    static void Main(string[] args)
    {
        Run();
        ReadLine();
    }
    static void Run()
    {
        var task = ComputeFileLengthAsync(null);
        WriteLine("Computing file length");
        WriteLine(task.Result);
        WriteLine("done!");
    }

    static async Task<int> ComputeFileLengthAsync(string fileName)
    {
        WriteLine("Before If");
        if (fileName == null)
        {
            WriteLine("Inside");
            throw new ArgumentNullException(nameof(fileName));
        }
        WriteLine("After");

        using (var fileStream = OpenText(fileName))
        {
            var content = await fileStream.ReadToEndAsync();
            return content.Length;
        }
    }
}

Dica: será impresso “Computing file length” no output.

Você sabe explicar o porquê? Que estratégia de implementação eu poderia seguir se eu quiser ter a exception quando chamar a função?

Compartilhe este insight:

Elemar Júnior

Sou fundador e CEO da EximiaCo e atuo como tech trusted advisor ajudando diversas empresas a gerar mais resultados através da tecnologia.

Elemar Júnior

Sou fundador e CEO da EximiaCo e atuo como tech trusted advisor ajudando diversas empresas a gerar mais resultados através da tecnologia.

Mais insights para o seu negócio

Veja mais alguns estudos e reflexões que podem gerar alguns insights para o seu negócio:

In this post, I would like to share my first attempt to create a (still) elementary search library. The source...
Um dos benefícios mais bacanas do programa MVP é o direito a participação no MVP Global Summit – evento anual,...
In this post, I will help you to set up your first RavenDB cluster. To be honest, it is not...
I worked a lot in the last months updating the RavenDB bootcamp to v4.x. My work is done (for a...
Na Guiando, os times já possuem certa maturidade com Scrum. Agora, com a adoção progressiva de princípios de Kanban estamos...
No post anterior, apresentamos o Apache NiFi e entendemos como é possível integrar aplicações através de fluxos de dados nessa...