TryParse without goto in c#

Viewed 40

I use this kind of code a lot and it works fine but apparently goto is spagetticode. It rewrite a sting to a double and then if it doesn't work ask try again and reloops it. Is there an other way that is better?

LoopCl:
    Console.WriteLine("Hur många Cl?");
    hereIsAStringVar= Console.ReadLine();

    if (double.TryParse(hereIsAStringVar, out hereIsADoubleVar))
    {

    }
    else 
    {
        Console.WriteLine("try again");
        goto LoopCl;
    }
0 Answers
Related