Search code examples
c#syntaxlanguage-designif-statement

Why does this string initialization in an if statement prevent me from printing?


i have little problem with if

{
    string nom;
    string ou;
    nom = "1";
    if (nom == "1")
    {
        nom +=1;
        ou = nom;
    }
    Console.Write(ou);
}

but i cant print ou value i dont know why


Solution

  • Another option is to set ou in an else:

    if (nom == "1")
    {
        nom +=1;
        ou = nom;
    } else 
    {
        ou = "blank value";
    }