What is the C# equivalent of NaN or IsNumeric?

后端 未结 15 1052
心在旅途
心在旅途 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:17

    I have a slightly different version which returns the number. I would guess that in most cases after testing the string you would want to use the number.

    public bool IsNumeric(string numericString, out Double numericValue)
    {
        if (Double.TryParse(numericString, out numericValue))
            return true;
        else
            return false;
    }
    

提交回复
热议问题