What is the C# equivalent of NaN or IsNumeric?

后端 未结 15 1038
心在旅途
心在旅途 2020-11-27 14:06

What is the most efficient way of testing an input string whether it contains a numeric value (or conversely Not A Number)? I guess I can use Double.Parse or a

15条回答
  •  没有蜡笔的小新
    2020-11-27 14:11

    I prefer something like this, it lets you decide what NumberStyle to test for.

    public static Boolean IsNumeric(String input, NumberStyles numberStyle) {
        Double temp;
        Boolean result = Double.TryParse(input, numberStyle, CultureInfo.CurrentCulture, out temp);
        return result;
    }
    

提交回复
热议问题