Checking if string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I'm wondering how you can check a string that supposed to represent a
numeric value.

e.g. in old VB6 there was a method IsNumeric().

Is there an equivelant in C#?

Many thanks for your answers in advance
Ant
 
Ant said:
Hi, I'm wondering how you can check a string that supposed to represent a
numeric value.

e.g. in old VB6 there was a method IsNumeric().

Is there an equivelant in C#?

Not really - you basically have to try to parse the string as a number
(eg using Double.TryParse).

If you really want to, you can add a reference to the
Microsoft.VisualBasic assembly, and use
Microsoft.VisualBasic.Information.IsNumeric().
 
try
{
int iValue = int.Parse(mystring);
}
catch(FormatException fe)
{
Console.WriteLine(mystring + " is not numeric");
}
 
Back
Top