Input string was not in a correct format #2

后端 未结 10 1261
一向
一向 2020-12-03 21:24
double temp;
temp = (double)Convert.ToDouble(\"1234.5678\");

Hey Lads and Ladies, I can\'t for the life of me figure out why the above line isn\'t

10条回答
  •  眼角桃花
    2020-12-03 22:06

    I recommend you use TryParse instead, so you don't need to handle parsing exceptions.

    double temp = 0;
    if (double.TryParse("123.456", out temp)
    {
        Console.WriteLine(string.Format("Parsed temp: {0}", temp);
    }
    else
    {
        Console.WriteLine("Input value was not able to be parsed.");
    }
    

提交回复
热议问题