из help VS:
Create the IsNumeric Function
In Visual C# .NET, you can use the Double.TryParse method to obtain functionality that is similar to IsNumeric. Double.TryParse converts the string representation of a number in a specified style and culture-specific format to its double-precision floating point number equivalent. To create the IsNumeric function:
Start Visual Studio .NET. On the File, point to New, and then click Project.
In the New Project dialog box, click Visual C# Projects under Project Type.
Under Templates, click Console Application, and then click OK. By default, Class1.cs is created.
At the end of the Class1 class, add the following code for the IsNumeric function:
// IsNumeric Function
static bool IsNumeric(object Expression)
{
// Variable to collect the Return value of the TryParse method.
bool isNum;
// Define variable to collect out parameter of the TryParse method. If the conversion fails, the out parameter is zero.
double retNum;
// The TryParse method converts a string in a specified style and culture-specific format to its double-precision floating point number equivalent.
// The TryParse method does not generate an exception if the conversion fails. If the conversion passes, True is returned. If it does not, False is returned.
isNum = Double.TryParse(Convert.ToString(Expression), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum );
return isNum;
}
|