Format exception when I am converting to Int32

前端 未结 5 1381
深忆病人
深忆病人 2020-12-22 15:32

While i am trying to convert a value to Int32, I get an error format exception, meaning the value is not in the proper format. I think I am converting a value in right forma

5条回答
  •  执念已碎
    2020-12-22 15:49

    You will get FormatException in cases such next:

    Convert.ToInt32("foo");
    Convert.ToInt32(5.5);
    

    because

    FormatException

    value does not consist of an optional sign followed by a sequence of digits (0 through 9).

    MSDN

提交回复
热议问题