我正在尝试检查字符串变量的值是否为双精度。
\n\n我已经看到这个现有问题(检查变量是否为双精度数据类型)及其答案,它们很棒,但我有一个不同的问题。
\n\npublic static bool IsDouble(string ValueToTest) \n {\n double Test;\n bool OutPut;\n OutPut = double.TryParse(ValueToTest, out Test);\n return OutPut;\n }\n
Run Code Online (Sandbox Code Playgroud)\n\n从上面的代码中,当 ValueToTest 为“-\xe2\x88\x9e”时,变量 Test 中得到的输出为“-Infinity”,并且该方法返回 true。
\n\n当 ValueToTest 为“NaN”时,我得到的输出为“NaN”。
\n\n它们都是 C# 中的“-\xe2\x88\x9e”和“NaN”双精度值吗?
\n\n还有一种方法可以仅检查实数(https://en.wikipedia.org/wiki/Real_number)并排除无穷大和 NaN?
\n