lundi 11 novembre 2019

Why Local variable might not be initialized before accessing

public void A()
{
    if (!(_s is string v))
        return;

    Console.WriteLine(v);
}

This code compiles good
But

public void A()
{
    if (false == _s is string v)
        return;

    Console.WriteLine(v); <-- 'Local variable 'v' might not be initialized before accessing'
}

But this returns compiler error
What's the reason?

Aucun commentaire:

Enregistrer un commentaire