Input string was not in a correct format

后端 未结 8 1304
滥情空心
滥情空心 2020-11-22 02:55

I\'m new with C#, I have some basic knowledge in Java but I can\'t get this code to run properly.

It\'s just a basic calculator, but when I run the program VS2008 gi

8条回答
  •  没有蜡笔的小新
    2020-11-22 03:12

    I ran into this exact exception, except it had nothing to do with parsing numerical inputs. So this isn't an answer to the OP's question, but I think it's acceptable to share the knowledge.

    I'd declared a string and was formatting it for use with JQTree which requires curly braces ({}). You have to use doubled curly braces for it to be accepted as a properly formatted string:

    string measurements = string.empty;
    measurements += string.Format(@"
        {{label: 'Measurement Name: {0}',
            children: [
                {{label: 'Measured Value: {1}'}},
                {{label: 'Min: {2}'}},
                {{label: 'Max: {3}'}},
                {{label: 'Measured String: {4}'}},
                {{label: 'Expected String: {5}'}},
            ]
        }},",
        drv["MeasurementName"] == null ? "NULL" : drv["MeasurementName"],
        drv["MeasuredValue"] == null ? "NULL" : drv["MeasuredValue"],
        drv["Min"] == null ? "NULL" : drv["Min"],
        drv["Max"] == null ? "NULL" : drv["Max"],
        drv["MeasuredString"] == null ? "NULL" : drv["MeasuredString"],
        drv["ExpectedString"] == null ? "NULL" : drv["ExpectedString"]);
    

    Hopefully this will help other folks who find this question but aren't parsing numerical data.

提交回复
热议问题