What is the C# equivalent of NaN or IsNumeric?

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

    You can still use the Visual Basic function in C#. The only thing you have to do is just follow my instructions shown below:

    1. Add the reference to the Visual Basic Library by right clicking on your project and selecting "Add Reference":

    enter image description here

    1. Then import it in your class as shown below:

      using Microsoft.VisualBasic;

    2. Next use it wherever you want as shown below:

                  if (!Information.IsNumeric(softwareVersion))
              {
                  throw new DataException(string.Format("[{0}] is an invalid App Version!  Only numeric values are supported at this time.", softwareVersion));
              }
      

    Hope, this helps and good luck!

提交回复
热议问题